#include "bms_Slave.h"
#include "rtwtypes.h"
#include <math.h>
#include "rt_nonfinite.h"
#include "Alarm_Recov_sys.h"
#include "Alarm_Recov_sys_cell.h"
#include "bms_Slave_Diagnose_system.h"
#include "bms_Slave_ChrgMode_Cal.h"
#include "bms_Slave_DC_ChrgSig.h"
#include "bms_Slave_SOP.h"
#include "ABI.h"
#include "ASW_SignalAdapt.h"
#include "APP_BSW.h"
#include "ABI_OSEK.h"
#include "multiword_types.h"
#include "bms_Slave_private.h"
#include "LookUp_S16_U32.h"
#include "mul_usu32_sat.h"
#include "uMultiWordMul.h"
#include "look1_iu32lu8n8tu8_binlcase.h"
#include "uLong2MultiWord.h"
#include "uMultiWordDivZero.h"
#include "MultiWord2uLong.h"
#include "look1_iu16lu16n16yu8tu_6zSHy4Dc.h"
#include "ASW_Signal.h"
#include "calPrms.h"
#include "SOC_GX.h"
#include "Balance.h"

#define bms_Slave_IN_Calibration1      ((uint8_T)1U)
#define bms_Slave_IN_Calibration_Result ((uint8_T)2U)
#define bms_Slave_IN_INI               ((uint8_T)3U)

#define bms_Slave_IN_Chrg_State        ((uint8_T)1U)
#define bms_Slave_IN_Emer_Delay        ((uint8_T)2U)
#define bms_Slave_IN_HV_Finish         ((uint8_T)3U)
#define bms_Slave_IN_INI_State         ((uint8_T)4U)
#define bms_Slave_IN_Initial           ((uint8_T)5U)
#define bms_Slave_IN_Relay_Close       ((uint8_T)6U)
#define bms_Slave_IN_Relay_Open        ((uint8_T)7U)
#define bms_Slave_IN_Standby           ((uint8_T)8U)

#define bms_Slave_IN_Chrg              ((uint8_T)1U)
#define bms_Slave_IN_No_Chrg           ((uint8_T)2U)

uint8_T fc_r_cmcWake_flg_0;
uint8_T fc_r_bmu_cmd_flg_0;
uint8_T fc_r_ChrgData_flg_0;
uint8_T fc_r_ParaSet_flg_0;
static uint8_T EEP_Data[41];
B_bms_Slave_T bms_Slave_B;
DW_bms_Slave_T bms_Slave_DW;
static RT_MODEL_bms_Slave_T bms_Slave_M_;
RT_MODEL_bms_Slave_T *const bms_Slave_M = &bms_Slave_M_;
uint8_T HV_State;
uint8_T Mode;
ABI_NVM ABI_NVMData;
ABI_Adc_Type ABI_AdcSamplingData;
ABI_DIDType ABI_DID;
ABI_WakeStateType ABI_WakeState;
CH_CAN_Flg_Type CH_CAN_Flg;
uint8_T fc_r_ChrgData_flg;
uint8_T fc_r_ParaSet_flg;
uint8_T fc_r_bmu_cmd_flg;
uint8_T fc_r_cmcWake_flg;
static void bms_Slave_CHCAN_Receive(void);
static void bms_Slave_CHCAN_Clear(void);
static void bms_Slave_INI_Rx(void);
static void bms_Slave_CHCAN_Receive(void)
{
  int32_T tmp;
  uint8_T Receive_Flg;
  Receive_Flg = (uint8_T)RTE_CAN_RecvCanDataById(0, 402846912, &bms_Slave_B.Chrger_CMC_Chrg_Data[0], &bms_Slave_DW.Chrger_CMC_Chrg_Len);
  if (Receive_Flg != 0) 
	{
    fc_r_ChrgData_flg = Receive_Flg;
  } 
	else if ((CH_CAN_Flg.fc_r_ChrgData_flg == 0) && (bms_Slave_DW.T_Rcv % 50 == 0)) 
	{
    fc_r_ChrgData_flg = 0U;
  }

  Receive_Flg = (uint8_T)RTE_CAN_RecvCanDataById(0, 402781376, &bms_Slave_B.Chrger_CMC_Wake_Data[0], &bms_Slave_DW.Chrger_CMC_Wake_len);
  if (Receive_Flg != 0) 
	{
    fc_r_cmcWake_flg = Receive_Flg;
  } 
	else if ((CH_CAN_Flg.fc_r_cmcWake_flg == 0) && (bms_Slave_DW.T_Rcv % 50 == 0))
  {
    fc_r_cmcWake_flg = 0U;
  }

  Receive_Flg = (uint8_T)RTE_CAN_RecvCanDataById(0, 521, &bms_Slave_B.BMU_CMD_Data[0], &bms_Slave_DW.BMU_CMD_Len);
  if (Receive_Flg != 0) 
	{
    fc_r_bmu_cmd_flg = Receive_Flg;
  } 
	else if ((CH_CAN_Flg.fc_r_bmu_cmd_flg == 0) && (bms_Slave_DW.T_Rcv % 10 == 0))
  {
    fc_r_bmu_cmd_flg = 0U;
  }

  tmp = bms_Slave_DW.T_Rcv + 1;
  if (bms_Slave_DW.T_Rcv + 1 > 255) 
  {
    tmp = 255;
  }

  bms_Slave_DW.T_Rcv = (uint8_T)tmp;
  if (bms_Slave_DW.T_Rcv >= 100) {
    bms_Slave_DW.T_Rcv = 0U;
  }
}

static void bms_Slave_CHCAN_Clear(void)
{
  int32_T i;
  for (i = 0; i < 8; i++) {
    bms_Slave_B.Chrger_CMC_Chrg_Data[i] = 0U;
    bms_Slave_B.Chrger_CMC_Wake_Data[i] = 0U;
    bms_Slave_B.BMU_CMD_Data[i] = 0U;
  }
}

static void bms_Slave_INI_Rx(void)
{
  bms_Slave_B.AFE_Signal.CellV_low_lv3_latch = 0U;
  bms_Slave_B.AFE_Signal.CellV_Over_lv3_latch = 0U;
  bms_Slave_B.AFE_Signal.SOH_low_lv1_latch = 0U;
  bms_Slave_B.AFE_Signal.SOH_low_lv2_latch = 0U;
  bms_Slave_B.AFE_Signal.Shunt_Zerodrift_latch = 0U;
  Rte_Write_UnderVoltageTh(CellV_UV_Th);
}

void bms_Slave_step(void)
{
  uint32_T rtb_Ah_IN;
  real32_T rtb_Use_SOC;
  real32_T rtb_Factor_CAP;
  uint8_T rtb_R_Rpt;
  uint8_T rtb_Factor_SOC95_keep;
  boolean_T rtb_Switch_ONOFF;
  uint64m_T tmp;
  uint64m_T tmp_0;
  uint64m_T tmp_1;
  uint64m_T tmp_2;
  uint64m_T tmp_3;
  uint64m_T tmp_4;
  real_T CellT_acc;
  int32_T i_0;
  int32_T rtb_Low_Current;
  real32_T rtb_Switch_i[10];
  real32_T Ref;
  real32_T Ref1;
  real32_T rtb_Divide6;
  real32_T rtb_Gain;
  real32_T rtb_Switch11;
  uint32_T rtb_DataTypeConversion_a[10];
  const uint32_T *rtb_Switch_a0_0;
  uint32_T CellV_acc;
  uint32_T rtb_Gain10;
  int16_T rtb_Switch2_c[10];
  uint16_T i;
  uint8_T Receive_Flg;
  uint8_T b_index;
  boolean_T rtb_RelationalOperator2_io[10];
  boolean_T rtb_Err_To_ShutDown_Delay;
  boolean_T rtb_HV_Contact_Cmd;
  boolean_T rtb_INI_To_Standby;
  boolean_T rtb_RelationalOperator;
  boolean_T rtb_RelationalOperator4_g;
  boolean_T rtb_RelayClose_To_HV_Finish;
  boolean_T rtb_RelayClose_To_HV_Finish_tmp;
  boolean_T tmp_5;
  boolean_T tmp_6;
  if (bms_Slave_DW.is_active_c9_bms_Slave == 0U) {
    bms_Slave_DW.is_active_c9_bms_Slave = 1U;
    bms_Slave_INI_Rx();
    bms_Slave_DW.T_n = 0U;
    bms_Slave_DW.T_Rcv = 0U;
    Rte_Read_EEData(&bms_Slave_DW.EEP_Data_b[0], 41);
    ABI_NVMData.RealSOC = (uint32_T)((bms_Slave_DW.EEP_Data_b[0] << 8) +
      bms_Slave_DW.EEP_Data_b[1]);
    ABI_NVMData.ActSOC = (uint32_T)((bms_Slave_DW.EEP_Data_b[2] << 8) +
      bms_Slave_DW.EEP_Data_b[3]);
    ABI_NVMData.SOCDisp = (uint32_T)((bms_Slave_DW.EEP_Data_b[4] << 8) +
      bms_Slave_DW.EEP_Data_b[5]);
    ABI_NVMData.SOH = (uint32_T)((bms_Slave_DW.EEP_Data_b[6] << 8) +
      bms_Slave_DW.EEP_Data_b[7]);
    i_0 = bms_Slave_DW.EEP_Data_b[8] << 24;
    rtb_Low_Current = bms_Slave_DW.EEP_Data_b[9] << 16;
    if (i_0 > MAX_int32_T - rtb_Low_Current) {
      i_0 = MAX_int32_T;
    } else {
      i_0 += rtb_Low_Current;
    }

    rtb_Low_Current = bms_Slave_DW.EEP_Data_b[10] << 8;
    if (i_0 > MAX_int32_T - rtb_Low_Current) {
      i_0 = MAX_int32_T;
    } else {
      i_0 += rtb_Low_Current;
    }

    rtb_Low_Current = bms_Slave_DW.EEP_Data_b[11];
    if (i_0 > MAX_int32_T - rtb_Low_Current) {
      i_0 = MAX_int32_T;
    } else {
      i_0 += rtb_Low_Current;
    }

    if (i_0 < 0) {
      i_0 = 0;
    }

    ABI_NVMData.BatteryPackChargeCapacity = (uint32_T)i_0;
    ABI_NVMData.SOC_Ave_Read = (uint16_T)((bms_Slave_DW.EEP_Data_b[12] << 8) +
      bms_Slave_DW.EEP_Data_b[13]);
    ABI_NVMData.Mileage = bms_Slave_DW.EEP_Data_b[14];
    ABI_NVMData.Mileage_Ave_Read = bms_Slave_DW.EEP_Data_b[15];
    ABI_NVMData.Power_Consom = (uint16_T)((bms_Slave_DW.EEP_Data_b[16] << 8) +
      bms_Slave_DW.EEP_Data_b[17]);
    ABI_NVMData.CurrOffset_Cal = (uint16_T)((bms_Slave_DW.EEP_Data_b[18] << 8) +
      bms_Slave_DW.EEP_Data_b[19]);
    ABI_NVMData.Target_SOC = bms_Slave_DW.EEP_Data_b[20];
    ABI_NVMData.VIN[0] = bms_Slave_DW.EEP_Data_b[21];
    ABI_NVMData.VIN[1] = bms_Slave_DW.EEP_Data_b[22];
    ABI_NVMData.VIN[2] = bms_Slave_DW.EEP_Data_b[23];
    ABI_NVMData.VIN[3] = bms_Slave_DW.EEP_Data_b[24];
    ABI_NVMData.VIN[4] = bms_Slave_DW.EEP_Data_b[25];
    ABI_NVMData.VIN[5] = bms_Slave_DW.EEP_Data_b[26];
    ABI_NVMData.VIN[6] = bms_Slave_DW.EEP_Data_b[27];
    ABI_NVMData.VIN[7] = bms_Slave_DW.EEP_Data_b[28];
    ABI_NVMData.VIN[8] = bms_Slave_DW.EEP_Data_b[29];
    ABI_NVMData.VIN[9] = bms_Slave_DW.EEP_Data_b[30];
    ABI_NVMData.VIN[10] = bms_Slave_DW.EEP_Data_b[31];
    ABI_NVMData.VIN[11] = bms_Slave_DW.EEP_Data_b[32];
    ABI_NVMData.VIN[12] = bms_Slave_DW.EEP_Data_b[33];
    ABI_NVMData.VIN[13] = bms_Slave_DW.EEP_Data_b[34];
    ABI_NVMData.VIN[14] = bms_Slave_DW.EEP_Data_b[35];
    ABI_NVMData.VIN[15] = bms_Slave_DW.EEP_Data_b[36];
    ABI_NVMData.VIN[16] = bms_Slave_DW.EEP_Data_b[37];
    ABI_NVMData.Chrg_Num = bms_Slave_DW.EEP_Data_b[38];
    ABI_NVMData.UsedSOC = bms_Slave_DW.EEP_Data_b[39];
    ABI_NVMData.FullChrg_Flg = bms_Slave_DW.EEP_Data_b[40];
    Rte_Send_DID_F190(&ABI_NVMData.VIN[0], 17);
  } else {
    i_0 = bms_Slave_DW.T_n + 1;
    if (bms_Slave_DW.T_n + 1 > 255) {
      i_0 = 255;
    }

    bms_Slave_DW.T_n = (uint8_T)i_0;
    ABI_AdcSamplingData.Bat_Vol = (uint32_T)(Rte_Read_BatVol() * 220 * 31 / 273
      + 700);
    ABI_AdcSamplingData.PackID_AD = (uint32_T)Rte_Read_PCB_AD_R();
    ABI_AdcSamplingData.PackID_AD = mul_usu32_sat(220,
      ABI_AdcSamplingData.PackID_AD) / 273U;
    ABI_AdcSamplingData.Current_AD = (uint16_T)Rte_Read_Current_Shut_AD(0);
    ABI_AdcSamplingData.BoardVoltage_mV = (uint16_T)Rte_Read_Supply_Vol();
    ABI_AdcSamplingData.BoardVoltage_mV = (uint16_T)((int32_T)
      (ABI_AdcSamplingData.BoardVoltage_mV / 273U) * 220);
    bms_Slave_B.AFE_Signal.CellV_Valid = (uint8_T)Rte_Read_CellV_Valid();
    bms_Slave_B.AFE_Signal.CellT_Valid = (uint8_T)Rte_Read_CellT_Valid();
    bms_Slave_B.AFE_Signal.Chain_Update = 0U;
    bms_Slave_B.AFE_Signal.Current_Valid = (uint8_T)Rte_Read_Current_Valid();
    bms_Slave_B.AFE_Signal.INI_Finish_flg = (uint8_T)Rte_Read_INI_Finish_flg();
    bms_Slave_B.AFE_Signal.CellV_Sample_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.ACAN_BUSOFF_flg = (uint8_T)Rte_Read_ACAN_BUSOFF_flg();
    bms_Slave_B.AFE_Signal.Balance_Diagnose_flg = 0U;
    ABI_WakeState.CP_WakeState = 0U;
    if (bms_Slave_DW.UnitDelay13_DSTATE) {
      bms_Slave_CHCAN_Clear();
    } else {
      bms_Slave_CHCAN_Receive();
    }

    Receive_Flg = (uint8_T)RTE_CAN_RecvCanDataById(0, 777,
      &bms_Slave_DW.Para_Set_BMS_Temp[0], &bms_Slave_DW.Para_Set_BMS_len);
    if (Receive_Flg != 0) {
      fc_r_ParaSet_flg_0 = Receive_Flg;
      for (i_0 = 0; i_0 < 8; i_0++) {
        bms_Slave_B.Para_Set_BMS[i_0] = bms_Slave_DW.Para_Set_BMS_Temp[i_0];
      }
    } else if ((CH_CAN_Flg.fc_r_ParaSet_flg == 1) && (bms_Slave_DW.T_n % 5 == 0))
    {
      fc_r_ParaSet_flg_0 = 0U;
      bms_Slave_B.Para_Set_BMS[7] = 0U;
    }

    Receive_Flg = (uint8_T)Rte_Get_DID_F190(&bms_Slave_DW.VIN_GET[0], 17);
    if (Receive_Flg != 0) {
      Receive_Flg = 0U;
      Rte_Send_DID_F190(&bms_Slave_DW.VIN_GET[0], 17);
      while (Receive_Flg < 16) {
        ABI_NVMData.VIN[Receive_Flg] = bms_Slave_DW.VIN_GET[Receive_Flg];
        Receive_Flg++;
      }
    }

    if ((bms_Slave_DW.UnitDelay36_DSTATE != 0) &&
        (bms_Slave_DW.UnitDelay36_DSTATE > ABI_NVMData.Chrg_Num)) {
      ABI_NVMData.Chrg_Num = bms_Slave_DW.UnitDelay36_DSTATE;
    }

    Receive_Flg = 0U;
    while ((Receive_Flg < 31) && (bms_Slave_DW.T_n >= 10) &&
           (bms_Slave_B.AFE_Signal.CellV_Valid == 0)) {
      i_0 = (int32_T)(((int32_T)Rte_Read_CellV_IN(Receive_Flg) << 2) +
                      Rte_Read_CellV_IN(Receive_Flg)) >> 5;
      if (i_0 < 0) {
        i_0 = 0;
      } else if (i_0 > 65535) {
        i_0 = 65535;
      }

      bms_Slave_B.CellV_IN[Receive_Flg] = (uint16_T)i_0;
      Receive_Flg++;
    }

    Receive_Flg = 0U;
    while ((Receive_Flg < 10) && (bms_Slave_DW.T_n >= 10) &&
           (bms_Slave_B.AFE_Signal.CellT_Valid == 0)) {
      Ref = (real32_T)(Rte_Read_Temp_Ref(0) * 0.05 + 6.8);
      Ref1 = (real32_T)(Rte_Read_Temp_Ref(1) * 0.05 + 6.8);
      if (Receive_Flg >= 6) {
        bms_Slave_B.CellT_AD_IN[Receive_Flg] = (real32_T)(Rte_Read_CellT_AD_IN
          (Receive_Flg) / 273 * 220);
        bms_Slave_B.CellT_AD_IN[Receive_Flg] =
          bms_Slave_B.CellT_AD_IN[Receive_Flg] * (real32_T)CellT_Temp_AD_R /
          (33000.0F - bms_Slave_B.CellT_AD_IN[Receive_Flg]);
      } else if (Receive_Flg < 3) {
        bms_Slave_B.CellT_AD_IN[Receive_Flg] = (real32_T)Rte_Read_CellT_AD_IN
          (Receive_Flg);
        bms_Slave_B.CellT_AD_IN[Receive_Flg] =
          bms_Slave_B.CellT_AD_IN[Receive_Flg] / (32768.0F -
          bms_Slave_B.CellT_AD_IN[Receive_Flg]) * Ref * 1000.0F;
      } else {
        bms_Slave_B.CellT_AD_IN[Receive_Flg] = (real32_T)Rte_Read_CellT_AD_IN
          (Receive_Flg);
        bms_Slave_B.CellT_AD_IN[Receive_Flg] =
          bms_Slave_B.CellT_AD_IN[Receive_Flg] / (32768.0F -
          bms_Slave_B.CellT_AD_IN[Receive_Flg]) * Ref1 * 1000.0F;
      }

      Receive_Flg++;
    }

    if (bms_Slave_DW.T_n % 10 == 0) {
      bms_Slave_B.Balance_State = (uint32_T)Rte_Read_Balance_State();
    }

    if (bms_Slave_DW.T_n >= 100) {
      bms_Slave_DW.T_n = 1U;
    }
  }

  for (i = 0U; i < bms_Slave_ConstB.Width_m; i++) {
    if (Channel_Connect[i] == 1) {
      bms_Slave_B.CellV_OUT[i] = bms_Slave_B.CellV_IN[i];
    } else {
      bms_Slave_B.CellV_OUT[i] = MAX_uint16_T;
    }
  }

  i = 0U;
  CellV_acc = 0U;
  bms_Slave_B.CellV_max = bms_Slave_B.CellV_OUT[0];
  bms_Slave_B.CellV_min = bms_Slave_B.CellV_OUT[0];
  while (i < bms_Slave_ConstB.Width) {
    if (Channel_Connect[i] == 1) {
      bms_Slave_B.CellV_OUT_p[i] = bms_Slave_B.CellV_OUT[i];
      rtb_Gain10 = CellV_acc + bms_Slave_B.CellV_OUT[i];
      if (rtb_Gain10 < CellV_acc) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10;
      if (bms_Slave_B.CellV_max <= bms_Slave_B.CellV_OUT[i]) {
        bms_Slave_B.CellV_max = bms_Slave_B.CellV_OUT[i];
      }

      if (bms_Slave_B.CellV_min >= bms_Slave_B.CellV_OUT[i]) {
        bms_Slave_B.CellV_min = bms_Slave_B.CellV_OUT[i];
      }
    } else {
      bms_Slave_B.CellV_OUT_p[i] = MAX_uint16_T;
    }

    i++;
  }

  if (CellV_num == 0U) {
    rtb_Gain10 = MAX_uint32_T;
  } else {
    rtb_Gain10 = CellV_acc / CellV_num;
  }

  if (rtb_Gain10 > 65535U) {
    rtb_Gain10 = 65535U;
  }

  bms_Slave_B.CellV_mean = (uint16_T)rtb_Gain10;
  for (i_0 = 0; i_0 < 10; i_0++) {
    if (bms_Slave_B.CellT_AD_IN[i_0] < 300000.0F) {
      rtb_Switch_i[i_0] = bms_Slave_B.CellT_AD_IN[i_0];
    } else {
      rtb_Switch_i[i_0] = 0.0F;
    }
  }

  if (CellT_AD_Type != 0) {
    CellV_acc = CellT_AD_100K[0];
    for (i_0 = 0; i_0 < 331; i_0++) {
      rtb_Gain10 = CellT_AD_100K[i_0 + 1];
      if (CellV_acc < rtb_Gain10) {
        CellV_acc = rtb_Gain10;
      }
    }

    rtb_Gain10 = CellV_acc + 1U;
  } else {
    CellV_acc = CellT_AD_10K[0];
    for (i_0 = 0; i_0 < 331; i_0++) {
      rtb_Gain10 = CellT_AD_10K[i_0 + 1];
      if (CellV_acc < rtb_Gain10) {
        CellV_acc = rtb_Gain10;
      }
    }

    rtb_Gain10 = CellV_acc + 1U;
  }

  for (i_0 = 0; i_0 < 10; i_0++) {
    rtb_RelationalOperator2_io[i_0] = (rtb_Switch_i[i_0] >= rtb_Gain10);
  }

  if (CellT_AD_Type != 0) {
    CellV_acc = CellT_AD_100K[0];
    for (i_0 = 0; i_0 < 331; i_0++) {
      rtb_Gain10 = CellT_AD_100K[i_0 + 1];
      if (CellV_acc > rtb_Gain10) {
        CellV_acc = rtb_Gain10;
      }
    }

    rtb_Gain10 = CellV_acc - 1U;
  } else {
    CellV_acc = CellT_AD_10K[0];
    for (i_0 = 0; i_0 < 331; i_0++) {
      rtb_Gain10 = CellT_AD_10K[i_0 + 1];
      if (CellV_acc > rtb_Gain10) {
        CellV_acc = rtb_Gain10;
      }
    }

    rtb_Gain10 = CellV_acc - 1U;
  }

  for (i_0 = 0; i_0 < 10; i_0++) {
    Ref = floorf(rtb_Switch_i[i_0]);
    if (rtIsNaNF(Ref) || rtIsInfF(Ref)) {
      Ref = 0.0F;
    } else {
      Ref = fmodf(Ref, 4.2949673E+9F);
    }

    rtb_DataTypeConversion_a[i_0] = Ref < 0.0F ? (uint32_T)-(int32_T)(uint32_T)
      -Ref : (uint32_T)Ref;
  }

  if (CellT_AD_Type != 0) {
    rtb_Switch_a0_0 = ((const uint32_T *)&CellT_AD_100K[0]);
  } else {
    rtb_Switch_a0_0 = ((const uint32_T *)&CellT_AD_10K[0]);
  }

  {
    int_T i1;
    const uint32_T *u0 = &rtb_DataTypeConversion_a[0];
    int16_T *y0 = &rtb_Switch2_c[0];
    for (i1=0; i1 < 10; i1++) {
      LookUp_S16_U32( &(y0[i1]), (const int16_T *)&CellT_Table[0], u0[i1],
                     &rtb_Switch_a0_0[0], 331U);
    }
  }

  for (i_0 = 0; i_0 < 10; i_0++) {
    int16_T rtb_Switch2_bv;
    rtb_Switch2_bv = rtb_Switch2_c[i_0];
    if (rtb_RelationalOperator2_io[i_0]) {
      rtb_Switch2_bv = -45;
    } else if (rtb_Switch_i[i_0] <= rtb_Gain10) {
      rtb_Switch2_bv = 130;
    }

    rtb_Switch2_c[i_0] = rtb_Switch2_bv;
  }

  for (i = 0U; i < bms_Slave_ConstB.Width_d; i++) {
    if (CellT_Channel_Connect[i] == 1) {
      bms_Slave_B.CellT_OUT[i] = rtb_Switch2_c[i];
    } else {
      bms_Slave_B.CellT_OUT[i] = -45;
    }
  }

  b_index = 0U;
  CellT_acc = 0.0;
  bms_Slave_B.CellT_max = bms_Slave_B.CellT_OUT[0];
  bms_Slave_B.CellT_min = bms_Slave_B.CellT_OUT[0];
  i_0 = Chip_num * 3;
  if (i_0 > 255) {
    i_0 = 255;
  }

  Receive_Flg = (uint8_T)i_0;
  while (b_index < Chip_num * Tempnum2chip) {
    if (bms_Slave_B.CellT_OUT[b_index] == -45) {
      i_0 = Receive_Flg - 1;
      if (Receive_Flg - 1 < 0) {
        i_0 = 0;
      }

      Receive_Flg = (uint8_T)i_0;
    } else {
      CellT_acc += (real_T)bms_Slave_B.CellT_OUT[b_index];
      if (bms_Slave_B.CellT_max <= bms_Slave_B.CellT_OUT[b_index]) {
        bms_Slave_B.CellT_max = bms_Slave_B.CellT_OUT[b_index];
      }

      if (bms_Slave_B.CellT_min >= bms_Slave_B.CellT_OUT[b_index]) {
        bms_Slave_B.CellT_min = bms_Slave_B.CellT_OUT[b_index];
      }
    }

    i_0 = b_index + 1;
    if (b_index + 1 > 255) {
      i_0 = 255;
    }

    b_index = (uint8_T)i_0;
  }

  if (CellT_num != Receive_Flg) {
    CellT_acc /= (real_T)Receive_Flg;
    if (CellT_acc < 32768.0) {
      if (CellT_acc >= -32768.0) {
        bms_Slave_B.CellT_mean = (int16_T)CellT_acc;
      } else {
        bms_Slave_B.CellT_mean = MIN_int16_T;
      }
    } else {
      bms_Slave_B.CellT_mean = MAX_int16_T;
    }
  } else {
    CellT_acc /= (real_T)CellT_num;
    if (CellT_acc < 32768.0) {
      if (CellT_acc >= -32768.0) {
        bms_Slave_B.CellT_mean = (int16_T)CellT_acc;
      } else {
        bms_Slave_B.CellT_mean = MIN_int16_T;
      }
    } else {
      bms_Slave_B.CellT_mean = MAX_int16_T;
    }
  }

  if (fc_r_cmcWake_flg == 1) {
    bms_Slave_B.Chrger_CMC_Wake_Pack.ID = 402781376U;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Length = 8U;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Extended = 1U;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Remote = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[0] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[1] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[2] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[3] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[4] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[5] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[6] = 0;
    bms_Slave_B.Chrger_CMC_Wake_Pack.Data[7] = 0;

    {
      (void) memcpy((bms_Slave_B.Chrger_CMC_Wake_Pack.Data),
                    &bms_Slave_B.Chrger_CMC_Wake_Data[0],
                    8 * sizeof(uint8_T));
    }

    {
      if ((8 == bms_Slave_B.Chrger_CMC_Wake_Pack.Length) &&
          (bms_Slave_B.Chrger_CMC_Wake_Pack.ID != INVALID_CAN_ID) ) {
        if ((402781376 == bms_Slave_B.Chrger_CMC_Wake_Pack.ID) && (1U ==
             bms_Slave_B.Chrger_CMC_Wake_Pack.Extended) ) {
          {
            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.Chrger_CMC_Wake_Pack.Data[0]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Open_The_Barn_door = result;
              }
            }
          }
        }
      }
    }

    CellT_acc = floor(bms_Slave_B.Open_The_Barn_door);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.Open_The_Barn_door_c = (uint8_T)(CellT_acc < 0.0 ? (int32_T)
      (uint8_T)-(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
  }

  Ref = floorf(bms_Slave_B.CurrOffset_Cal_Add);
  tmp_5 = rtIsNaNF(Ref);
  tmp_6 = rtIsInfF(Ref);
  if (tmp_5 || tmp_6) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(Ref, 4.2949673E+9F);
  }

  if ((ABI_AdcSamplingData.Current_AD & 32768U) != 0U) {
    i_0 = ABI_AdcSamplingData.Current_AD - 65521;
  } else {
    i_0 = ABI_AdcSamplingData.Current_AD;
  }

  rtb_Low_Current = (rtb_Switch11 < 0.0F ? -(int32_T)(uint32_T)-rtb_Switch11 :
                     (int32_T)(uint32_T)rtb_Switch11) - i_0 * 20;
  if ((bms_Slave_DW.UnitDelay37_DSTATE == 1) && ((rtb_Low_Current > 0) ||
       (rtb_Low_Current < -100))) {
    bms_Slave_B.Current = rtb_Low_Current + Static_Current;
  } else {
    bms_Slave_B.Current = Static_Current;
  }

  bms_Slave_B.CellT_Valid = (bms_Slave_B.AFE_Signal.CellT_Valid == 0);
  bms_Slave_B.LogicalOperator20 = (bms_Slave_B.AFE_Signal.CellV_Valid == 0);
  rtb_RelationalOperator4_g = (bms_Slave_B.CellV_max >= CellV_limit);
  bms_Slave_Alarm_Recov_sys(rtb_RelationalOperator4_g,
    !rtb_RelationalOperator4_g, 50, 1, &bms_Slave_B.Alarm_flg_a,
    &bms_Slave_DW.sf_Alarm_Recov_sys2);
  rtb_RelationalOperator4_g = (ABI_AdcSamplingData.Bat_Vol >= (uint32_T)
    CellV_limit * CellV_num + 1000U);
  Alarm_Recov_sys_cell(rtb_RelationalOperator4_g, !rtb_RelationalOperator4_g, 50,
                       1, &bms_Slave_B.Alarm_flg_e,
                       &bms_Slave_DW.sf_Alarm_Recov_sys10);
  Alarm_Recov_sys(bms_Slave_B.LogicalOperator20, !bms_Slave_B.LogicalOperator20,
                  400, 1, &bms_Slave_B.Alarm_flg_h,
                  &bms_Slave_DW.sf_Alarm_Recov_sys11);
  if (bms_Slave_B.Alarm_flg_a || bms_Slave_B.Alarm_flg_e) {
    bms_Slave_B.CellV_TgtReach = 1U;
  } else if (bms_Slave_B.Alarm_flg_h) {
    bms_Slave_B.CellV_TgtReach = 2U;
  } else {
    bms_Slave_B.CellV_TgtReach = 0U;
  }

  if (fc_r_bmu_cmd_flg == 1) {
    bms_Slave_B.BMU_CMD_Pack.ID = 521U;
    bms_Slave_B.BMU_CMD_Pack.Length = 8U;
    bms_Slave_B.BMU_CMD_Pack.Extended = 0U;
    bms_Slave_B.BMU_CMD_Pack.Remote = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[0] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[1] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[2] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[3] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[4] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[5] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[6] = 0;
    bms_Slave_B.BMU_CMD_Pack.Data[7] = 0;

    {
      (void) memcpy((bms_Slave_B.BMU_CMD_Pack.Data), &bms_Slave_B.BMU_CMD_Data[0],
                    8 * sizeof(uint8_T));
    }

    {
      if ((8 == bms_Slave_B.BMU_CMD_Pack.Length) && (bms_Slave_B.BMU_CMD_Pack.ID
           != INVALID_CAN_ID) ) {
        if ((521 == bms_Slave_B.BMU_CMD_Pack.ID) && (0U ==
             bms_Slave_B.BMU_CMD_Pack.Extended) ) {
          {
            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[1]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.BMU_Life = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint16_T unpackedValue = 0;

                {
                  uint16_T tempValue = (uint16_T) (0);

                  {
                    tempValue = tempValue | (uint16_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[3]);
                    tempValue = tempValue | (uint16_T)((uint16_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[2]) << 8);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Balance_Cmd = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[0]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.CMD_Pack_ID = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[4]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.ErrorCode_Clear = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[6]) & (uint8_T)(0xC0U)) >>
                      6);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Relay_Contrl_Single = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.BMU_CMD_Pack.Data[5]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Relay_Contrl = result;
              }
            }
          }
        }
      }
    }

    CellT_acc = floor(bms_Slave_B.Relay_Contrl_Single);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.Relay_Contrl_Single_h = (uint8_T)(CellT_acc < 0.0 ? (int32_T)
      (uint8_T)-(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
    CellT_acc = floor(bms_Slave_B.Relay_Contrl);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.Relay_Contrl_i = (uint8_T)(CellT_acc < 0.0 ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
    CellT_acc = floor(bms_Slave_B.ErrorCode_Clear);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 65536.0);
    }

    bms_Slave_B.ErrorCode_Clear_c = (uint16_T)(CellT_acc < 0.0 ? (int32_T)
      (uint16_T)-(int16_T)(uint16_T)-CellT_acc : (int32_T)(uint16_T)CellT_acc);
    CellT_acc = floor(bms_Slave_B.CMD_Pack_ID);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.CMD_Pack_ID_o = (uint8_T)(CellT_acc < 0.0 ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
  }

  bms_Slave_B.LogicalOperator3 = (bms_Slave_B.ErrorCode_Clear_c == 0);
  bms_Slave_Diagnose_system();
  CH_CAN_Flg.fc_r_ParaSet_flg = fc_r_ParaSet_flg_0;
  CH_CAN_Flg.fc_r_ChrgData_flg = fc_r_ChrgData_flg;
  CH_CAN_Flg.fc_r_cmcWake_flg = fc_r_cmcWake_flg;
  CH_CAN_Flg.fc_r_bmu_cmd_flg = fc_r_bmu_cmd_flg;
  bms_Slave_B.LogicalOperator9 = ((CH_CAN_Flg.fc_r_cmcWake_flg == 1) &&
    (bms_Slave_DW.UnitDelay5_DSTATE <= 99.0F) &&
    (bms_Slave_B.Open_The_Barn_door_c == 1));
  rtb_RelationalOperator = (bms_Slave_B.DisChrgMOS_Open_Cmd ||
    bms_Slave_B.ChrgMOS_Open_Cmd);
  rtb_INI_To_Standby = ((bms_Slave_B.AFE_Signal.INI_Finish_flg == 0) &&
                        (bms_Slave_B.CellV_min >= CellV_Min_Con) &&
                        (bms_Slave_B.CellV_max <= CellV_Max_Con) &&
                        (ABI_AdcSamplingData.Bat_Vol >= Bat_Con) &&
                        (bms_Slave_B.CellT_max < CellT_Over_LV3) &&
                        (bms_Slave_B.CellT_min > CellT_Low_LV3) &&
                        (!rtb_RelationalOperator));
  i_0 = bms_Slave_B.CMD_Pack_ID_o & bms_Slave_B.Relay_Contrl_i;
  rtb_HV_Contact_Cmd = (((((CH_CAN_Flg.fc_r_cmcWake_flg == 0) && (i_0 != 0)) ||
    bms_Slave_B.LogicalOperator9) && rtb_INI_To_Standby) ||
                        (bms_Slave_B.Relay_Contrl_Single_h != 0));
  rtb_Err_To_ShutDown_Delay = ((bms_Slave_B.ChrgMOS_Open_Cmd ||
    bms_Slave_B.DisChrgMOS_Open_Cmd) && (bms_Slave_B.Relay_Contrl_Single_h == 0));
  rtb_RelayClose_To_HV_Finish_tmp = !rtb_Err_To_ShutDown_Delay;
  rtb_RelayClose_To_HV_Finish = ((bms_Slave_DW.UnitDelay4_DSTATE_b == 1) &&
    rtb_RelayClose_To_HV_Finish_tmp);
  if (fc_r_ChrgData_flg == 1) {
    bms_Slave_B.Chrger_CMC_Chrg_Pack.ID = 402846912U;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Length = 8U;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Extended = 1U;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Remote = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[0] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[1] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[2] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[3] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[4] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[5] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[6] = 0;
    bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[7] = 0;

    {
      (void) memcpy((bms_Slave_B.Chrger_CMC_Chrg_Pack.Data),
                    &bms_Slave_B.Chrger_CMC_Chrg_Data[0],
                    8 * sizeof(uint8_T));
    }

    {
      if ((8 == bms_Slave_B.Chrger_CMC_Chrg_Pack.Length) &&
          (bms_Slave_B.Chrger_CMC_Chrg_Pack.ID != INVALID_CAN_ID) ) {
        if ((402846912 == bms_Slave_B.Chrger_CMC_Chrg_Pack.ID) && (1U ==
             bms_Slave_B.Chrger_CMC_Chrg_Pack.Extended) ) {
          {
            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[0]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Chrg_Mark = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.Chrger_CMC_Chrg_Pack.Data[1]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.Chrger_Alarm = result;
              }
            }
          }
        }
      }
    }

    CellT_acc = floor(bms_Slave_B.Chrger_Alarm);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.Chrger_Alarm_e = (uint8_T)(CellT_acc < 0.0 ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
    CellT_acc = floor(bms_Slave_B.Chrg_Mark);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.Chrg_Mark_a = (uint8_T)(CellT_acc < 0.0 ? (int32_T)(uint8_T)
      -(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)CellT_acc);
  }

  rtb_RelationalOperator4_g = ((((bms_Slave_B.Chrger_Alarm_e != 0) &&
    (CH_CAN_Flg.fc_r_cmcWake_flg == 1)) || ((bms_Slave_B.Chrg_Mark_a == 0) &&
    (CH_CAN_Flg.fc_r_cmcWake_flg == 1)) || rtb_RelationalOperator || ((i_0 == 0)
    && (bms_Slave_B.Relay_Contrl_Single_h == 0) && (CH_CAN_Flg.fc_r_cmcWake_flg ==
    0) && (bms_Slave_B.Chrg_Mark_a == 0))) && (bms_Slave_B.Relay_Contrl_Single_h
    == 0));
  rtb_Switch11 = floorf(Factor_LowVol * (real32_T)
                        ABI_AdcSamplingData.BoardVoltage_mV);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  if (bms_Slave_DW.is_active_c13_bms_Slave == 0U) {
    bms_Slave_DW.is_active_c13_bms_Slave = 1U;
    bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Initial;
    bms_Slave_DW.T_e = 0U;
    Mode = 1U;
    HV_State = 0U;
    Rte_Write_DC_Contact_Control(0);
    bms_Slave_B.BMS_PwrTrainConnectSta = 0U;
    bms_Slave_B.Relay_En = 0U;
  } else {
    switch (bms_Slave_DW.is_c13_bms_Slave) {
     case bms_Slave_IN_Chrg_State:
      Mode = 6U;
      HV_State = 3U;
      if ((!bms_Slave_B.LogicalOperator9) || rtb_RelationalOperator4_g) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_HV_Finish;
        Mode = 5U;
        HV_State = 2U;
        bms_Slave_B.BMS_PwrTrainConnectSta = 1U;
      }
      break;

     case bms_Slave_IN_Emer_Delay:
      Mode = 7U;
      HV_State = 4U;
      if (rtb_RelayClose_To_HV_Finish_tmp && (bms_Slave_DW.T_e < 500U)) {
        bms_Slave_DW.T_e = 0U;
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_HV_Finish;
        Mode = 5U;
        HV_State = 2U;
        bms_Slave_B.BMS_PwrTrainConnectSta = 1U;
      } else {
        if (bms_Slave_B.Current < 0) {
          i_0 = -bms_Slave_B.Current;
        } else {
          i_0 = bms_Slave_B.Current;
        }

        if ((((i <= 18000) || (i > 32000) || rtb_Err_To_ShutDown_Delay) && (i_0 <=
              3000)) || (bms_Slave_DW.T_e >= 500U)) {
          bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Relay_Open;
          Mode = 8U;
          bms_Slave_DW.T_e = 0U;
          HV_State = 4U;
          Rte_Write_DC_Contact_Control(0);
          bms_Slave_B.Relay_En = 0U;
          bms_Slave_B.BMS_PwrTrainConnectSta = 0U;
        } else {
          rtb_Gain10 = bms_Slave_DW.T_e + 1U;
          if (bms_Slave_DW.T_e + 1U < bms_Slave_DW.T_e) {
            rtb_Gain10 = MAX_uint32_T;
          }

          bms_Slave_DW.T_e = rtb_Gain10;
        }
      }
      break;

     case bms_Slave_IN_HV_Finish:
      Mode = 5U;
      HV_State = 2U;
      bms_Slave_B.BMS_PwrTrainConnectSta = 1U;
      if (rtb_Err_To_ShutDown_Delay) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Emer_Delay;
        Mode = 7U;
        bms_Slave_DW.T_e = 0U;
        HV_State = 4U;
      } else if (bms_Slave_B.LogicalOperator9 && (bms_Slave_B.Current <= -1000))
      {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Chrg_State;
        Mode = 6U;
        HV_State = 3U;
      } else if (rtb_RelationalOperator4_g) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Relay_Open;
        Mode = 8U;
        bms_Slave_DW.T_e = 0U;
        HV_State = 4U;
        Rte_Write_DC_Contact_Control(0);
        bms_Slave_B.Relay_En = 0U;
        bms_Slave_B.BMS_PwrTrainConnectSta = 0U;
      }
      break;

     case bms_Slave_IN_INI_State:
      HV_State = 1U;
      Mode = 2U;
      if (rtb_INI_To_Standby) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Standby;
        bms_Slave_DW.T_e = 0U;
        Mode = 3U;
        bms_Slave_B.SOC_Correct_Flag = false;
      } else if (bms_Slave_DW.T_e >= 200U) {
        bms_Slave_B.SOC_Correct_Flag = false;
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Emer_Delay;
        Mode = 7U;
        bms_Slave_DW.T_e = 0U;
        HV_State = 4U;
      } else {
        rtb_Gain10 = bms_Slave_DW.T_e + 1U;
        if (bms_Slave_DW.T_e + 1U < bms_Slave_DW.T_e) {
          rtb_Gain10 = MAX_uint32_T;
        }

        bms_Slave_DW.T_e = rtb_Gain10;
      }
      break;

     case bms_Slave_IN_Initial:
      Mode = 1U;
      HV_State = 0U;
      bms_Slave_B.BMS_PwrTrainConnectSta = 0U;
      bms_Slave_B.Relay_En = 0U;
      if (bms_Slave_DW.T_e >= 20U) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_INI_State;
        bms_Slave_DW.T_e = 0U;
        HV_State = 1U;
        bms_Slave_B.SOC_Correct_Flag = true;
        Mode = 2U;
      } else {
        rtb_Gain10 = bms_Slave_DW.T_e + 1U;
        if (bms_Slave_DW.T_e + 1U < bms_Slave_DW.T_e) {
          rtb_Gain10 = MAX_uint32_T;
        }

        bms_Slave_DW.T_e = rtb_Gain10;
      }
      break;

     case bms_Slave_IN_Relay_Close:
      Mode = 4U;
      HV_State = 1U;
      bms_Slave_B.Relay_En = 1U;
      if ((!rtb_RelayClose_To_HV_Finish) && (bms_Slave_DW.T_e >= 100U)) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Emer_Delay;
        Mode = 7U;
        bms_Slave_DW.T_e = 0U;
        HV_State = 4U;
      } else if (rtb_RelayClose_To_HV_Finish || (bms_Slave_DW.T_e >= 100U)) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_HV_Finish;
        Mode = 5U;
        HV_State = 2U;
        bms_Slave_B.BMS_PwrTrainConnectSta = 1U;
      } else {
        rtb_Gain10 = bms_Slave_DW.T_e + 1U;
        if (bms_Slave_DW.T_e + 1U < bms_Slave_DW.T_e) {
          rtb_Gain10 = MAX_uint32_T;
        }

        bms_Slave_DW.T_e = rtb_Gain10;
      }
      break;

     case bms_Slave_IN_Relay_Open:
      Mode = 8U;
      HV_State = 4U;
      bms_Slave_B.Relay_En = 0U;
      bms_Slave_B.BMS_PwrTrainConnectSta = 0U;
      if (rtb_HV_Contact_Cmd) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Relay_Close;
        bms_Slave_DW.T_e = 0U;
        Mode = 4U;
        HV_State = 1U;
        Rte_Write_DC_Contact_Control(1);
        bms_Slave_B.Relay_En = 1U;
      }
      break;

     default:
      Mode = 3U;
      if (rtb_HV_Contact_Cmd) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Relay_Close;
        bms_Slave_DW.T_e = 0U;
        Mode = 4U;
        HV_State = 1U;
        Rte_Write_DC_Contact_Control(1);
        bms_Slave_B.Relay_En = 1U;
      } else if (bms_Slave_DW.T_e >= 200U) {
        bms_Slave_DW.is_c13_bms_Slave = bms_Slave_IN_Emer_Delay;
        Mode = 7U;
        bms_Slave_DW.T_e = 0U;
        HV_State = 4U;
      } else {
        rtb_Gain10 = bms_Slave_DW.T_e + 1U;
        if (bms_Slave_DW.T_e + 1U < bms_Slave_DW.T_e) {
          rtb_Gain10 = MAX_uint32_T;
        }

        bms_Slave_DW.T_e = rtb_Gain10;
      }
      break;
    }
  }

  bms_Slave_B.RelationalOperator1 = (HV_State == 3);
  rtb_INI_To_Standby = (RTC_time.resetflag != 0);
  rtb_RelationalOperator = (RTC_time.timevalidflag != 0);
  rtb_Divide6 = ABI_NVMData.UsedSOC;
  rtb_Switch11 = 0.01F * (real32_T)ABI_NVMData.RealSOC;
  Ref1 = 0.01F * (real32_T)ABI_NVMData.ActSOC;
  if (fc_r_ParaSet_flg_0 == 1) {
    bms_Slave_B.Para_Set_BMS_Pack.ID = 777U;
    bms_Slave_B.Para_Set_BMS_Pack.Length = 8U;
    bms_Slave_B.Para_Set_BMS_Pack.Extended = 0U;
    bms_Slave_B.Para_Set_BMS_Pack.Remote = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[0] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[1] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[2] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[3] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[4] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[5] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[6] = 0;
    bms_Slave_B.Para_Set_BMS_Pack.Data[7] = 0;

    {
      (void) memcpy((bms_Slave_B.Para_Set_BMS_Pack.Data),
                    &bms_Slave_B.Para_Set_BMS[0],
                    8 * sizeof(uint8_T));
    }

    {
      if ((8 == bms_Slave_B.Para_Set_BMS_Pack.Length) &&
          (bms_Slave_B.Para_Set_BMS_Pack.ID != INVALID_CAN_ID) ) {
        if ((777 == bms_Slave_B.Para_Set_BMS_Pack.ID) && (0U ==
             bms_Slave_B.Para_Set_BMS_Pack.Extended) ) {
          {
            {
              real64_T outValue = 0;

              {
                uint16_T unpackedValue = 0;

                {
                  uint16_T tempValue = (uint16_T) (0);

                  {
                    tempValue = tempValue | (uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[3]);
                    tempValue = tempValue | (uint16_T)((uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[2]) << 8);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                result = result * 0.1;
                bms_Slave_B.BMS_BatSOC_Actl_Set = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[7]) & (uint8_T)(0x2U))
                      >> 1);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.BMS_BatSOC_Actl_Set_Valid = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint16_T unpackedValue = 0;

                {
                  uint16_T tempValue = (uint16_T) (0);

                  {
                    tempValue = tempValue | (uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[1]);
                    tempValue = tempValue | (uint16_T)((uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[0]) << 8);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                result = result * 0.1;
                bms_Slave_B.BMS_BatSOC_Rpt_Set = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)((uint8_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[7]) & (uint8_T)(0x1U));
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.BMS_BatSOC_Rpt_Set_Valid = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[4]);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                result = result * 0.1;
                bms_Slave_B.BMS_CurrFixCoeff_Set = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[7]) & (uint8_T)(0x4U))
                      >> 2);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.BMS_CurrFixCoeff_Set_Valid = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint16_T unpackedValue = 0;

                {
                  uint16_T tempValue = (uint16_T) (0);

                  {
                    tempValue = tempValue | (uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[6]);
                    tempValue = tempValue | (uint16_T)((uint16_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[5]) << 8);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                result = result + -10000.0;
                bms_Slave_B.BMS_CurrOffset_Set = result;
              }
            }

            {
              real64_T outValue = 0;

              {
                uint8_T unpackedValue = 0;

                {
                  uint8_T tempValue = (uint8_T) (0);

                  {
                    tempValue = tempValue | (uint8_T)((uint8_T)((uint8_T)
                      (bms_Slave_B.Para_Set_BMS_Pack.Data[7]) & (uint8_T)(0x8U))
                      >> 3);
                  }

                  unpackedValue = tempValue;
                }

                outValue = (real64_T) (unpackedValue);
              }

              {
                real64_T result = (real64_T) outValue;
                bms_Slave_B.BMS_CurrOffset_Set_Valid = result;
              }
            }
          }
        }
      }
    }

    CellT_acc = floor(bms_Slave_B.BMS_CurrOffset_Set);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 4.294967296E+9);
    }

    bms_Slave_B.BMS_CurrOffset_Set_i = CellT_acc < 0.0 ? -(int32_T)(uint32_T)
      -CellT_acc : (int32_T)(uint32_T)CellT_acc;
    CellT_acc = floor(bms_Slave_B.BMS_CurrOffset_Set_Valid);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.BMS_CurrOffset_Set_Valid_k = (uint8_T)(CellT_acc < 0.0 ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)
      CellT_acc);
    bms_Slave_B.BMS_BatSOC_Actl_Set_f = (real32_T)
      bms_Slave_B.BMS_BatSOC_Actl_Set;
    CellT_acc = floor(bms_Slave_B.BMS_BatSOC_Actl_Set_Valid);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.BMS_BatSOC_Actl_Set_Valid_l = (uint8_T)(CellT_acc < 0.0 ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)
      CellT_acc);
    bms_Slave_B.BMS_BatSOC_Rpt_Set_o = (real32_T)bms_Slave_B.BMS_BatSOC_Rpt_Set;
    CellT_acc = floor(bms_Slave_B.BMS_BatSOC_Rpt_Set_Valid);
    if (rtIsNaN(CellT_acc) || rtIsInf(CellT_acc)) {
      CellT_acc = 0.0;
    } else {
      CellT_acc = fmod(CellT_acc, 256.0);
    }

    bms_Slave_B.BMS_BatSOC_Rpt_Set_Valid_a = (uint8_T)(CellT_acc < 0.0 ?
      (int32_T)(uint8_T)-(int8_T)(uint8_T)-CellT_acc : (int32_T)(uint8_T)
      CellT_acc);
  }

  if (bms_Slave_DW.UnitDelay30_DSTATE != 0) {
    Receive_Flg = 0U;
    b_index = 0U;
  } else {
    Receive_Flg = bms_Slave_B.BMS_BatSOC_Rpt_Set_Valid_a;
    b_index = bms_Slave_B.BMS_BatSOC_Actl_Set_Valid_l;
  }

  rtb_Gain = 0.01F * (real32_T)ABI_NVMData.SOCDisp;
  bms_Slave_B.SOH = bms_Slave_DW.UnitDelay15_DSTATE;
  SOC_GX(&RTC_time_value.R, &ABI_NVMData.BMSStoredTime.R,
         &bms_Slave_B.AFE_Signal.INI_Finish_flg,
         &bms_Slave_DW.UnitDelay1_DSTATE_i, &rtb_INI_To_Standby,
         &ABI_NVMData.FullChrg_Flg, &rtb_RelationalOperator, &rtb_Divide6,
         &rtb_Switch11, &Ref1, &bms_Slave_B.CellV_min, &bms_Slave_B.CellV_max,
         &bms_Slave_B.CellT_Valid, &bms_Slave_B.CellT_mean,
         &bms_Slave_B.CellV_TgtReach, &bms_Slave_B.RelationalOperator1,
         &Receive_Flg, &b_index, &b_index, &bms_Slave_B.BMS_BatSOC_Rpt_Set_o,
         &bms_Slave_B.BMS_BatSOC_Actl_Set_f, &bms_Slave_B.BMS_BatSOC_Actl_Set_f,
         &rtb_Gain, &bms_Slave_B.Current, &bms_Slave_B.CellT_min,
         &bms_Slave_B.CellT_min, &bms_Slave_B.SOH, &bms_Slave_B.LogicalOperator9,
         &bms_Slave_B.LogicalOperator20, &bms_Slave_B.Real_SOC_Max,
         &bms_Slave_DW.UnitDelay10_DSTATE, &bms_Slave_B.SOC_Act,
         &bms_Slave_B.SOC_Rpt, &rtb_Use_SOC, &rtb_Switch_ONOFF, &rtb_Factor_CAP,
         &rtb_R_Rpt, &rtb_Ah_IN, &rtb_Factor_SOC95_keep,
         &bms_Slave_B.DB_OCV_Condition, &(bms_Slave_DW.SOC_InstanceData.rtb),
         &(bms_Slave_DW.SOC_InstanceData.rtdw));
  rtb_Switch11 = floorf(100.0F * bms_Slave_B.Real_SOC_Max);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[0] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[1] = (uint8_T)(i & 255);
  rtb_Switch11 = floorf(100.0F * bms_Slave_DW.UnitDelay10_DSTATE);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[2] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[3] = (uint8_T)(i & 255);
  rtb_Switch11 = floorf(100.0F * bms_Slave_B.SOC_Rpt);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[4] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[5] = (uint8_T)(i & 255);
  rtb_Switch11 = floorf(100.0F * bms_Slave_B.SOH);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[6] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[7] = (uint8_T)(i & 255);
  if (ABI_DID.writeAccumulatedBatteryPackChargeCapacity_flg != 0) {
    bms_Slave_DW.UnitDelay7_DSTATE = 1U;
  }

  if ((bms_Slave_B.Current < 0) && (bms_Slave_DW.UnitDelay2_DSTATE == 6)) {
    bms_Slave_DW.UnitDelay10_DSTATE_m = (real32_T)bms_Slave_B.Current * 0.01F /
      36000.0F + bms_Slave_DW.UnitDelay4_DSTATE;
    bms_Slave_DW.UnitDelay5_DSTATE_a = fabsf(bms_Slave_DW.UnitDelay10_DSTATE_m);
  } else if (bms_Slave_DW.UnitDelay2_DSTATE == 0) {
    bms_Slave_DW.UnitDelay10_DSTATE_m = 0.0F;
  }

  Ref1 = 0.1F * (real32_T)ABI_NVMData.BatteryPackChargeCapacity;
  Ref1 += bms_Slave_DW.UnitDelay5_DSTATE_a / 100.0F;
  if (bms_Slave_DW.UnitDelay7_DSTATE != 0) {
    bms_Slave_B.Switch9 = 0.1F * (real32_T)
      ABI_DID.writeAccumulatedBatteryPackChargeCapacity;
  } else {
    bms_Slave_B.Switch9 = Ref1;
  }

  rtb_Switch11 = floorf(10.0F * bms_Slave_B.Switch9);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 4.2949673E+9F);
  }

  rtb_Gain10 = rtb_Switch11 < 0.0F ? (uint32_T)-(int32_T)(uint32_T)-rtb_Switch11
    : (uint32_T)rtb_Switch11;
  EEP_Data[8] = (uint8_T)((rtb_Gain10 & 4278190080U) >> 24);
  EEP_Data[9] = (uint8_T)((rtb_Gain10 & 16711680U) >> 16);
  EEP_Data[10] = (uint8_T)((rtb_Gain10 & 65280U) >> 8);
  EEP_Data[11] = (uint8_T)(rtb_Gain10 & 255U);
  if (bms_Slave_ConstB.LogicalOperator1) {
    bms_Slave_DW.UnitDelay_DSTATE_m = 0.0F;
  } else if (HV_State != 3) {
    bms_Slave_DW.UnitDelay_DSTATE_m += 0.001F * (real32_T)
      ABI_AdcSamplingData.Bat_Vol * (0.001F * (real32_T)bms_Slave_B.Current) /
      360000.0F;
  }

  bms_Slave_DW.UnitDelay15_DSTATE_e = ((bms_Slave_ConstB.RelationalOperator3 &&
    (bms_Slave_DW.UnitDelay2_DSTATE_f != 0)) ||
    bms_Slave_DW.UnitDelay15_DSTATE_e);
  if (bms_Slave_DW.UnitDelay15_DSTATE_e) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = 0.1F * (real32_T)ABI_NVMData.Power_Consom;
  }

  rtb_Divide6 = bms_Slave_DW.UnitDelay_DSTATE_m + rtb_Switch11;
  rtb_Switch11 = 0.01F * (real32_T)ABI_NVMData.SOC_Ave_Read;
  if (bms_Slave_DW.is_active_c16_bms_Slave == 0U) {
    bms_Slave_DW.is_active_c16_bms_Slave = 1U;
    bms_Slave_DW.SOC_Store = bms_Slave_B.SOC_Rpt;
    bms_Slave_DW.Mileage_Store = ABI_NVMData.Mileage;
    if (rtb_Switch11 != 0.0F) {
      bms_Slave_B.SOC_Ave = rtb_Switch11;
    } else {
      bms_Slave_B.SOC_Ave = 1.25F;
    }

    rtb_Gain = ABI_NVMData.Mileage_Ave_Read;
  } else {
    rtb_Gain = bms_Slave_B.SOC_Rpt / bms_Slave_B.SOC_Ave;
    i_0 = ABI_NVMData.Mileage;
    rtb_Gain10 = (uint32_T)i_0 - bms_Slave_DW.Mileage_Store;
    if (rtb_Gain10 > (uint32_T)i_0) {
      rtb_Gain10 = 0U;
    }

    if ((int32_T)rtb_Gain10 >= 1) {
      bms_Slave_B.SOC_Ave = (real32_T)((bms_Slave_B.SOC_Rpt -
        bms_Slave_DW.SOC_Store) * 0.1 + bms_Slave_B.SOC_Ave * 0.9);
      bms_Slave_DW.SOC_Store = bms_Slave_B.SOC_Rpt;
      bms_Slave_DW.Mileage_Store = ABI_NVMData.Mileage;
    }

    if (bms_Slave_B.SOC_Ave == 0.0F) {
      bms_Slave_B.SOC_Ave = 1.25F;
    }
  }

  bms_Slave_DW.UnitDelay2_DSTATE_f = 0U;
  rtb_Switch11 = floorf(100.0F * bms_Slave_B.SOC_Ave);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[12] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[13] = (uint8_T)(i & 255);
  rtb_Switch11 = ceilf(bms_Slave_B.SOC_Rpt * (real32_T)Max_Mileage / 100.0F);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 256.0F);
  }

  Receive_Flg = (uint8_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint8_T)-(int8_T)
    (uint8_T)-rtb_Switch11 : (int32_T)(uint8_T)rtb_Switch11);
  if (Receive_Flg <= Max_Mileage) {
    EEP_Data[14] = Receive_Flg;
  } else {
    EEP_Data[14] = Max_Mileage;
  }

  rtb_Switch11 = floorf(rtb_Gain);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 256.0F);
  }

  EEP_Data[15] = (uint8_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint8_T)-(int8_T)
    (uint8_T)-rtb_Switch11 : (int32_T)(uint8_T)rtb_Switch11);
  rtb_Switch11 = floorf(10.0F * rtb_Divide6);
  if (rtIsNaNF(rtb_Switch11) || rtIsInfF(rtb_Switch11)) {
    rtb_Switch11 = 0.0F;
  } else {
    rtb_Switch11 = fmodf(rtb_Switch11, 65536.0F);
  }

  i = (uint16_T)(rtb_Switch11 < 0.0F ? (int32_T)(uint16_T)-(int16_T)(uint16_T)
                 -rtb_Switch11 : (int32_T)(uint16_T)rtb_Switch11);
  EEP_Data[16] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[17] = (uint8_T)(i & 255);
  if (tmp_5 || tmp_6) {
    Ref = 0.0F;
  } else {
    Ref = fmodf(Ref, 65536.0F);
  }

  i = (uint16_T)((Ref < 0.0F ? (int32_T)(int16_T)-(int16_T)(uint16_T)-Ref :
                  (int32_T)(int16_T)(uint16_T)Ref) + 10000);
  EEP_Data[18] = (uint8_T)((uint32_T)i >> 8);
  EEP_Data[19] = (uint8_T)(i & 255);
  if (bms_Slave_ConstB.LogicalOperator167) {
    b_index = 0U;
  } else {
    rtb_RelationalOperator = (ABI_NVMData.Target_SOC >= 50);
    rtb_INI_To_Standby = (ABI_NVMData.Target_SOC <= 100);
    if (rtb_INI_To_Standby && rtb_RelationalOperator) {
      b_index = ABI_NVMData.Target_SOC;
    } else {
      b_index = 100U;
    }
  }

  EEP_Data[20] = b_index;
  for (i_0 = 0; i_0 < 17; i_0++) {
    EEP_Data[i_0 + 21] = ABI_NVMData.VIN[i_0];
  }

  EEP_Data[38] = 0U;
  Ref = floorf(rtb_Use_SOC);
  if (rtIsNaNF(Ref) || rtIsInfF(Ref)) {
    Ref = 0.0F;
  } else {
    Ref = fmodf(Ref, 256.0F);
  }

  EEP_Data[39] = (uint8_T)(Ref < 0.0F ? (int32_T)(uint8_T)-(int8_T)(uint8_T)-Ref
    : (int32_T)(uint8_T)Ref);
  if (bms_Slave_DW.UnitDelay3_DSTATE < 100.0F) {
    bms_Slave_DW.UnitDelay26_DSTATE = 0U;
  } else if (bms_Slave_B.CellV_TgtReach == 1) {
    bms_Slave_DW.UnitDelay26_DSTATE = 1U;
  }

  rtb_RelationalOperator = ((ABI_NVMData.FullChrg_Flg != 0) &&
    (bms_Slave_DW.UnitDelay3_DSTATE >= 100.0F));
  EEP_Data[40] = (uint8_T)((bms_Slave_DW.UnitDelay26_DSTATE != 0) ||
    rtb_RelationalOperator);
  if (bms_Slave_DW.is_active_c37_bms_Slave == 0U) {
    bms_Slave_DW.is_active_c37_bms_Slave = 1U;
    bms_Slave_DW.is_c37_bms_Slave = bms_Slave_IN_No_Chrg;
    bms_Slave_DW.T = 0U;
    bms_Slave_B.Chrg_Sta = 1U;
  } else if (bms_Slave_DW.is_c37_bms_Slave == bms_Slave_IN_Chrg) {
    if (((bms_Slave_DW.UnitDelay5_DSTATE >= 100.0F) &&
         (CH_CAN_Flg.fc_r_cmcWake_flg == 1)) || rtb_RelationalOperator4_g ||
        bms_Slave_B.AC_ChrgDisable || (bms_Slave_DW.T >= 2880000U)) {
      bms_Slave_DW.is_c37_bms_Slave = bms_Slave_IN_No_Chrg;
      bms_Slave_DW.T = 0U;
      bms_Slave_B.Chrg_Sta = 1U;
    } else if (bms_Slave_B.Current < -100) {
      rtb_Gain10 = bms_Slave_DW.T + 1U;
      if (bms_Slave_DW.T + 1U < bms_Slave_DW.T) {
        rtb_Gain10 = MAX_uint32_T;
      }

      bms_Slave_DW.T = rtb_Gain10;
    }
  } else if (bms_Slave_B.LogicalOperator9) {
    bms_Slave_DW.is_c37_bms_Slave = bms_Slave_IN_Chrg;
    bms_Slave_B.Chrg_Sta = 0U;
    bms_Slave_DW.T = 0U;
  }

  bms_Slave_B.LogicalOperator20 = ((CH_CAN_Flg.fc_r_cmcWake_flg == 1) &&
    (bms_Slave_B.Open_The_Barn_door_c == 1));
  rtb_Divide6 = 0.01F * (real32_T)ABI_NVMData.SOH;
  if (rtb_Divide6 != 0.0F) {
    rtb_Switch11 = rtb_Divide6 / 100.0F;
  } else {
    rtb_Switch11 = 1.0F;
  }

  Ref = floorf(Ref1 / ((real32_T)Capacity_Rate * rtb_Switch11));
  if (rtIsNaNF(Ref) || rtIsInfF(Ref)) {
    Ref = 0.0F;
  } else {
    Ref = fmodf(Ref, 65536.0F);
  }

  bms_Slave_B.Cycle_Num = (uint16_T)(Ref < 0.0F ? (int32_T)(uint16_T)-(int16_T)
    (uint16_T)-Ref : (int32_T)(uint16_T)Ref);
  Ref1 = fabsf((real32_T)bms_Slave_B.CellV_max - bms_Slave_DW.UnitDelay1_DSTATE);
  rtb_RelationalOperator4_g = (Ref1 > 30.0F);
  bms_Slave_Alarm_Recov_sys(rtb_RelationalOperator4_g,
    !rtb_RelationalOperator4_g, 200, 1, &bms_Slave_B.Alarm_flg_jl,
    &bms_Slave_DW.sf_Alarm_Recov_sys3);
  if (bms_Slave_B.Alarm_flg_jl || (Ref1 <= 30.0F)) {
    bms_Slave_DW.UnitDelay1_DSTATE = bms_Slave_B.CellV_max;
  }

  bms_Slave_ChrgMode_Cal();
  bms_Slave_DC_ChrgSig();
  bms_Slave_B.UnitDelay17 = bms_Slave_DW.UnitDelay17_DSTATE;
  bms_Slave_B.UnitDelay21 = bms_Slave_DW.UnitDelay21_DSTATE;
  bms_Slave_SOP();
  if (ABI_AdcSamplingData.PackID_AD < ABI_AdcSamplingData.BoardVoltage_mV) {
    rtb_Gain10 = PACK_ID_AD_R;
    uMultiWordMul(&ABI_AdcSamplingData.PackID_AD, 1, &rtb_Gain10, 1,
                  &tmp_0.chunks[0U], 2);
    uLong2MultiWord(ABI_AdcSamplingData.BoardVoltage_mV -
                    ABI_AdcSamplingData.PackID_AD, &tmp_1.chunks[0U], 2);
    uMultiWordDivZero(&tmp_0.chunks[0U], 2, &tmp_1.chunks[0U], 2, &tmp.chunks[0U],
                      2, &tmp_2.chunks[0U], 2, &tmp_3.chunks[0U], 2,
                      &tmp_4.chunks[0U], 2);
    rtb_Gain10 = MultiWord2uLong(&tmp.chunks[0U]);
  } else {
    rtb_Gain10 = 0U;
  }

  Receive_Flg = look1_iu32lu8n8tu8_binlcase(rtb_Gain10, (const uint32_T *)
    &Pack_AD_Param[0], (const uint8_T *)&Pack_ID_CAL[0], 18U);
  rtb_RelationalOperator4_g = (bms_Slave_B.CellV_max < CellV_limit);
  bms_Slave_Alarm_Recov_sys(rtb_RelationalOperator4_g,
    !rtb_RelationalOperator4_g, 100, 1, &rtb_RelationalOperator,
    &bms_Slave_DW.sf_Alarm_Recov_sys3_i);
  for (b_index = 0U; b_index < 6; b_index++) {
    if (b_index > (Chip_num << 2) - 1) {
      bms_Slave_B.CellT_out[b_index] = bms_Slave_B.CellT_mean;
    } else if (bms_Slave_B.CellT_OUT[b_index] == -45) {
      bms_Slave_B.CellT_out[b_index] = bms_Slave_B.CellT_mean;
    } else {
      bms_Slave_B.CellT_out[b_index] = bms_Slave_B.CellT_OUT[b_index];
    }
  }

  for (i_0 = 0; i_0 < 32; i_0++) {
    bms_Slave_B.CellV_Connect[i_0] = (Channel_Connect[i_0] != 0);
  }

  if (bms_Slave_DW.counter % 5 == 0) {
    b_index = bms_Slave_B.DTC_ErrCode[0];
    for (i_0 = 0; i_0 < 79; i_0++) {
      uint8_T u1;
      u1 = bms_Slave_B.DTC_ErrCode[i_0 + 1];
      if (b_index < u1) {
        b_index = u1;
      }
    }

    if (b_index > 0) {
      boolean_T exitg1;
      exitg1 = false;
      while ((!exitg1) && (bms_Slave_DW.i <= 80)) {
        b_index = bms_Slave_B.DTC_ErrCode[bms_Slave_DW.i - 1];
        if (b_index > 0) {
          bms_Slave_B.BMS_Error_Code = b_index;
          i_0 = (int32_T)(bms_Slave_DW.i + 1U);
          if (bms_Slave_DW.i + 1U > 255U) {
            i_0 = 255;
          }

          bms_Slave_DW.i = (uint8_T)i_0;
          exitg1 = true;
        } else {
          i_0 = (int32_T)(bms_Slave_DW.i + 1U);
          if (bms_Slave_DW.i + 1U > 255U) {
            i_0 = 255;
          }

          bms_Slave_DW.i = (uint8_T)i_0;
        }
      }

      if (bms_Slave_DW.i == 81) {
        bms_Slave_DW.i = 1U;
      }
    } else {
      bms_Slave_B.BMS_Error_Code = 0U;
    }

    rtb_RelationalOperator4_g = (bms_Slave_B.LogicalOperator9 ||
      bms_Slave_B.RelationalOperator1);
    rtb_RelationalOperator = (bms_Slave_B.Err_Level_n <= 7);
    rtb_INI_To_Standby = (bms_Slave_B.ErrorCode_Clear_c != 0);
    if (((!rtb_RelationalOperator4_g) && bms_Slave_DW.UnitDelay3_DSTATE_pu &&
         rtb_RelationalOperator) || (rtb_RelationalOperator4_g &&
         (!bms_Slave_DW.UnitDelay1_DSTATE_b) && rtb_RelationalOperator) ||
        (rtb_INI_To_Standby && (bms_Slave_B.Err_Level_n <= 6))) {
      bms_Slave_B.Err_Level_a = 0U;
    } else {
      if (rtb_INI_To_Standby && (bms_Slave_B.Err_Level_n <= 5)) {
        b_index = 0U;
      } else {
        b_index = bms_Slave_B.Err_Level_n;
      }

      if (b_index >= 7) {
        bms_Slave_B.Err_Level_a = 3U;
      } else if (b_index == 6) {
        bms_Slave_B.Err_Level_a = 2U;
      } else {
        bms_Slave_B.Err_Level_a = (uint8_T)(b_index == 5);
      }
    }

    bms_Slave_DW.UnitDelay3_DSTATE_pu = rtb_RelationalOperator4_g;
    bms_Slave_DW.UnitDelay1_DSTATE_b = rtb_RelationalOperator4_g;
    bms_Slave_B.Gain_m = 0.001F * (real32_T)bms_Slave_B.Current;
    bms_Slave_B.Switch = (uint8_T)((Receive_Flg < 1) || (Receive_Flg > 8));
    bms_Slave_B.CMC_Current_Falt_Pack.ID = 609U;
    bms_Slave_B.CMC_Current_Falt_Pack.Length = 8U;
    bms_Slave_B.CMC_Current_Falt_Pack.Extended = 0U;
    bms_Slave_B.CMC_Current_Falt_Pack.Remote = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Current_Falt_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.BMS_Error_Code);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[7] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_1);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[2] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_2);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[3] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_3);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[4] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_4);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[5] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain_m;
          result = (result - -300.0F) * (1 / 0.01F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[1] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Current_Falt_Pack.Data[0] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Switch);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          if (packingValue > (uint8_T)(3)) {
            packedValue = (uint8_T) 3;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[6] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[6] | (uint8_T)((uint8_T)
                (packedValue & (uint8_T)0x3U));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Relay_En);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          if (packingValue > (uint8_T)(3)) {
            packedValue = (uint8_T) 3;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_Current_Falt_Pack.Data[6] =
                bms_Slave_B.CMC_Current_Falt_Pack.Data[6] | (uint8_T)((uint8_T)
                ((uint8_T)(packedValue & (uint8_T)0x3U) << 2));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Current_Falt_Pack.Length) &&
          (bms_Slave_B.CMC_Current_Falt_Pack.ID != INVALID_CAN_ID) ) {
        if ((609 == bms_Slave_B.CMC_Current_Falt_Pack.ID) && (0U ==
             bms_Slave_B.CMC_Current_Falt_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Current_Falt_Data[0],
                        bms_Slave_B.CMC_Current_Falt_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Current_Falt_ID = bms_Slave_B.CMC_Current_Falt_Pack.ID;
          bms_Slave_B.CMC_Current_Falt_Len =
            bms_Slave_B.CMC_Current_Falt_Pack.Length;
        }
      }
    }

    if (!bms_Slave_B.LogicalOperator20) {
      if ((Receive_Flg >= 1) && (Receive_Flg <= 8)) {
        rtb_Gain10 = bms_Slave_B.CMC_Current_Falt_ID + Receive_Flg;
        if (rtb_Gain10 < bms_Slave_B.CMC_Current_Falt_ID) {
          rtb_Gain10 = MAX_uint32_T;
        }

        CellV_acc = rtb_Gain10 - 1U;
        if (rtb_Gain10 - 1U > rtb_Gain10) {
          CellV_acc = 0U;
        }

        RTE_CAN_SendCanDataById(0, CellV_acc,
          &bms_Slave_B.CMC_Current_Falt_Data[0],
          bms_Slave_B.CMC_Current_Falt_Len);
      } else {
        RTE_CAN_SendCanDataById(0, 608, &bms_Slave_B.CMC_Current_Falt_Data[0],
          bms_Slave_B.CMC_Current_Falt_Len);
      }
    }
  }

  if (bms_Slave_DW.counter % 10 == 0) {
    Balance(&rtCP_Constant50_Value_o, &bms_Slave_B.CellV_OUT_p[0],
            &bms_Slave_B.CellV_min, &bms_Slave_B.CellV_max,
            &bms_Slave_B.CellT_max, &bms_Slave_B.CellT_min,
            &bms_Slave_B.CellT_max, &bms_Slave_B.CellT_min,
            &bms_Slave_B.AFE_Signal.CellV_Sample_lost_flg,
            &bms_Slave_B.RelationalOperator1,
            &bms_Slave_B.AFE_Signal.Chain_Update, &bms_Slave_B.SOC_Act,
            &bms_Slave_B.AFE_Signal.Balance_Diagnose_flg,
            &bms_Slave_B.Balance_State, &bms_Slave_B.CellV_Connect[0],
            &bms_Slave_B.Bal_State, &bms_Slave_B.Bal_Cmd[0],
            &bms_Slave_B.Balance_o3, &(bms_Slave_DW.Balance_InstanceData.rtb),
            &(bms_Slave_DW.Balance_InstanceData.rtdw));
    bms_Slave_B.CMC_CellT_SOC_Pack.ID = 577U;
    bms_Slave_B.CMC_CellT_SOC_Pack.Length = 8U;
    bms_Slave_B.CMC_CellT_SOC_Pack.Extended = 0U;
    bms_Slave_B.CMC_CellT_SOC_Pack.Remote = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[0] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[1] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[2] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[3] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[4] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[5] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[6] = 0;
    bms_Slave_B.CMC_CellT_SOC_Pack.Data[7] = 0;

    {
      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.CellT_out[0]);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[0] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[0] | (uint8_T)(packedValue);
            }
          }
        }
      }

      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.CellT_out[1]);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[1] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[1] | (uint8_T)(packedValue);
            }
          }
        }
      }

      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.CellT_out[2]);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[2] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[2] | (uint8_T)(packedValue);
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.SOC_Act;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(1023)) {
            packedValue = (uint16_T) 1023;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[5] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[5] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFU) << 4));
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[4] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x3F0U) >> 4));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Real_SOC_Max;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(1023)) {
            packedValue = (uint16_T) 1023;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[4] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x3U) << 6));
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[3] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[3] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x3FCU) >> 2));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.SOC_Rpt;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(1023)) {
            packedValue = (uint16_T) 1023;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[6] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x3FU) << 2));
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[5] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[5] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x3C0U) >> 6));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.SOH;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(1023)) {
            packedValue = (uint16_T) 1023;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[7] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellT_SOC_Pack.Data[6] =
                bms_Slave_B.CMC_CellT_SOC_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0x300U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_CellT_SOC_Pack.Length) &&
          (bms_Slave_B.CMC_CellT_SOC_Pack.ID != INVALID_CAN_ID) ) {
        if ((577 == bms_Slave_B.CMC_CellT_SOC_Pack.ID) && (0U ==
             bms_Slave_B.CMC_CellT_SOC_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_CellT_SOC_Data[0],
                        bms_Slave_B.CMC_CellT_SOC_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_CellT_SOC_ID = bms_Slave_B.CMC_CellT_SOC_Pack.ID;
          bms_Slave_B.CMC_CellT_SOC_Len = bms_Slave_B.CMC_CellT_SOC_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain11_o = 0.001F * bms_Slave_B.Con_AllowDisChrg_Current;
    bms_Slave_B.Gain10_b = 0.001F * bms_Slave_B.Con_AllowChrg_Current;
    bms_Slave_B.Gain9_l = 0.001F * bms_Slave_DW.UnitDelay25_DSTATE;
    bms_Slave_B.Gain8_e = 0.001F * bms_Slave_DW.UnitDelay27_DSTATE;
    bms_Slave_B.Max_Con_Current_Pack.ID = 593U;
    bms_Slave_B.Max_Con_Current_Pack.Length = 8U;
    bms_Slave_B.Max_Con_Current_Pack.Extended = 0U;
    bms_Slave_B.Max_Con_Current_Pack.Remote = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[0] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[1] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[2] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[3] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[4] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[5] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[6] = 0;
    bms_Slave_B.Max_Con_Current_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain11_o;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(4095)) {
            packedValue = (uint16_T) 4095;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.Max_Con_Current_Pack.Data[3] =
                bms_Slave_B.Max_Con_Current_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.Max_Con_Current_Pack.Data[2] =
                bms_Slave_B.Max_Con_Current_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain10_b;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(4095)) {
            packedValue = (uint16_T) 4095;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.Max_Con_Current_Pack.Data[7] =
                bms_Slave_B.Max_Con_Current_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.Max_Con_Current_Pack.Data[6] =
                bms_Slave_B.Max_Con_Current_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain9_l;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(4095)) {
            packedValue = (uint16_T) 4095;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.Max_Con_Current_Pack.Data[1] =
                bms_Slave_B.Max_Con_Current_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.Max_Con_Current_Pack.Data[0] =
                bms_Slave_B.Max_Con_Current_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain8_e;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(4095)) {
            packedValue = (uint16_T) 4095;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.Max_Con_Current_Pack.Data[5] =
                bms_Slave_B.Max_Con_Current_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.Max_Con_Current_Pack.Data[4] =
                bms_Slave_B.Max_Con_Current_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.Max_Con_Current_Pack.Length) &&
          (bms_Slave_B.Max_Con_Current_Pack.ID != INVALID_CAN_ID) ) {
        if ((593 == bms_Slave_B.Max_Con_Current_Pack.ID) && (0U ==
             bms_Slave_B.Max_Con_Current_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.Max_Con_Current_Data[0],
                        bms_Slave_B.Max_Con_Current_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.Max_Con_Current_ID = bms_Slave_B.Max_Con_Current_Pack.ID;
          bms_Slave_B.Max_Con_Current_Len =
            bms_Slave_B.Max_Con_Current_Pack.Length;
        }
      }
    }

    if ((!bms_Slave_B.LogicalOperator20) && ((Receive_Flg >= 1) && (Receive_Flg <=
          8))) {
      rtb_Gain10 = bms_Slave_B.CMC_CellT_SOC_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.CMC_CellT_SOC_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.CMC_CellT_SOC_Data[0],
        bms_Slave_B.CMC_CellT_SOC_Len);
      rtb_Gain10 = bms_Slave_B.Max_Con_Current_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.Max_Con_Current_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.Max_Con_Current_Data[0],
        bms_Slave_B.Max_Con_Current_Len);
    }

    if (bms_Slave_DW.is_active_c25_bms_Slave == 0U) {
      bms_Slave_DW.is_active_c25_bms_Slave = 1U;
      bms_Slave_DW.SOC_Store_m = bms_Slave_B.Real_SOC_Max;
      fc_r_ParaSet_flg = 0U;
    } else {
      if ((fc_r_ParaSet_flg_0 == 1) && (bms_Slave_DW.UnitDelay33_DSTATE == 0) &&
          (fabsf(bms_Slave_B.Real_SOC_Max - bms_Slave_DW.SOC_Store_m) >= 1.0F))
      {
        bms_Slave_DW.SOC_Store_m = bms_Slave_B.Real_SOC_Max;
        Rte_Write_EEData(&EEP_Data[0], 41);
        fc_r_ParaSet_flg = 1U;
      }

      if ((fabsf(bms_Slave_B.Real_SOC_Max - bms_Slave_DW.SOC_Store_m) >= 1.0F) ||
          (((HV_State == 5) && (bms_Slave_DW.UnitDelay4_DSTATE_bl != 5)) ||
           ((bms_Slave_DW.UnitDelay22_DSTATE == 0) &&
            (bms_Slave_B.CellV_TgtReach == 1)) ||
           ((bms_Slave_DW.UnitDelay34_DSTATE == 0) && (bms_Slave_B.Relay_En == 1))))
      {
        bms_Slave_DW.SOC_Store_m = bms_Slave_B.Real_SOC_Max;
        Rte_Write_EEData(&EEP_Data[0], 41);
        fc_r_ParaSet_flg = 0U;
      }
    }

    bms_Slave_DW.UnitDelay4_DSTATE_bl = HV_State;
    bms_Slave_DW.UnitDelay22_DSTATE = bms_Slave_B.CellV_TgtReach;
    bms_Slave_DW.UnitDelay34_DSTATE = bms_Slave_B.Relay_En;
    bms_Slave_DW.UnitDelay33_DSTATE = fc_r_ParaSet_flg_0;
  }

  if (bms_Slave_DW.counter % 50 == 0) {
    bms_Slave_B.ShiftArithmetic = (uint8_T)(bms_Slave_DW.UnitDelay37_DSTATE << 3);
    bms_Slave_B.Gain3 = 0.001F * (real32_T)CELLV_REFMAX;
    bms_Slave_B.Gain24 = 0.001F * bms_Slave_DW.UnitDelay27_DSTATE;
    bms_Slave_B.BMS_Chrg_Request_Pack.ID = 402768116U;
    bms_Slave_B.BMS_Chrg_Request_Pack.Length = 8U;
    bms_Slave_B.BMS_Chrg_Request_Pack.Extended = 1U;
    bms_Slave_B.BMS_Chrg_Request_Pack.Remote = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[0] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[1] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[2] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[3] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[4] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[5] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[6] = 0;
    bms_Slave_B.BMS_Chrg_Request_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Chrg_Sta);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[4] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.ShiftArithmetic);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[7] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain3;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[6] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[6] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[5] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[5] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain24;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[3] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[2] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.DC_ChrgVol;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[1] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.BMS_Chrg_Request_Pack.Data[0] =
                bms_Slave_B.BMS_Chrg_Request_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.BMS_Chrg_Request_Pack.Length) &&
          (bms_Slave_B.BMS_Chrg_Request_Pack.ID != INVALID_CAN_ID) ) {
        if ((402768116 == bms_Slave_B.BMS_Chrg_Request_Pack.ID) && (1U ==
             bms_Slave_B.BMS_Chrg_Request_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.BMS_Chrg_Request_Data[0],
                        bms_Slave_B.BMS_Chrg_Request_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.BMS_Chrg_Request_ID = bms_Slave_B.BMS_Chrg_Request_Pack.ID;
          bms_Slave_B.BMS_Chrg_Request_Len =
            bms_Slave_B.BMS_Chrg_Request_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain4 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[0];
    bms_Slave_B.Gain5 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[1];
    bms_Slave_B.Gain6 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[2];
    bms_Slave_B.Gain7 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[3];
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.ID = 402833652U;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain4;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain5;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain6;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain7;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Cell_1_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Cell_1_Pack.ID != INVALID_CAN_ID) ) {
        if ((402833652 == bms_Slave_B.CMC_Chrger_Cell_1_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Cell_1_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Cell_1_Data[0],
                        bms_Slave_B.CMC_Chrger_Cell_1_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Cell_1_ID =
            bms_Slave_B.CMC_Chrger_Cell_1_Pack.ID;
          bms_Slave_B.CMC_Chrger_Cell_1_Len =
            bms_Slave_B.CMC_Chrger_Cell_1_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain8 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[4];
    bms_Slave_B.Gain9 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[5];
    bms_Slave_B.Gain10 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[6];
    bms_Slave_B.Gain11 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[7];
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.ID = 402899188U;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain8;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain9;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain10;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain11;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Cell_2_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Cell_2_Pack.ID != INVALID_CAN_ID) ) {
        if ((402899188 == bms_Slave_B.CMC_Chrger_Cell_2_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Cell_2_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Cell_2_Data[0],
                        bms_Slave_B.CMC_Chrger_Cell_2_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Cell_2_ID =
            bms_Slave_B.CMC_Chrger_Cell_2_Pack.ID;
          bms_Slave_B.CMC_Chrger_Cell_2_Len =
            bms_Slave_B.CMC_Chrger_Cell_2_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain12 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[9];
    bms_Slave_B.Gain13 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[10];
    bms_Slave_B.Gain14 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[11];
    bms_Slave_B.Gain15 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[8];
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.ID = 402964724U;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain12;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain13;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain14;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain15;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Cell_3_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Cell_3_Pack.ID != INVALID_CAN_ID) ) {
        if ((402964724 == bms_Slave_B.CMC_Chrger_Cell_3_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Cell_3_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Cell_3_Data[0],
                        bms_Slave_B.CMC_Chrger_Cell_3_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Cell_3_ID =
            bms_Slave_B.CMC_Chrger_Cell_3_Pack.ID;
          bms_Slave_B.CMC_Chrger_Cell_3_Len =
            bms_Slave_B.CMC_Chrger_Cell_3_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain16 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[12];
    bms_Slave_B.Gain17 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[13];
    bms_Slave_B.Gain18 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[14];
    bms_Slave_B.Gain19 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[15];
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.ID = 403030260U;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain16;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain17;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain18;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain19;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Cell_4_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Cell_4_Pack.ID != INVALID_CAN_ID) ) {
        if ((403030260 == bms_Slave_B.CMC_Chrger_Cell_4_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Cell_4_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Cell_4_Data[0],
                        bms_Slave_B.CMC_Chrger_Cell_4_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Cell_4_ID =
            bms_Slave_B.CMC_Chrger_Cell_4_Pack.ID;
          bms_Slave_B.CMC_Chrger_Cell_4_Len =
            bms_Slave_B.CMC_Chrger_Cell_4_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain20 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[16];
    bms_Slave_B.Gain21 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[17];
    bms_Slave_B.Gain22 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[18];
    bms_Slave_B.Gain23 = 0.001F * (real32_T)bms_Slave_B.CellV_OUT_p[19];
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.ID = 403095796U;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain20;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain21;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain22;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain23;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Cell_5_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Cell_5_Pack.ID != INVALID_CAN_ID) ) {
        if ((403095796 == bms_Slave_B.CMC_Chrger_Cell_5_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Cell_5_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Cell_5_Data[0],
                        bms_Slave_B.CMC_Chrger_Cell_5_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Cell_5_ID =
            bms_Slave_B.CMC_Chrger_Cell_5_Pack.ID;
          bms_Slave_B.CMC_Chrger_Cell_5_Len =
            bms_Slave_B.CMC_Chrger_Cell_5_Pack.Length;
        }
      }
    }

    bms_Slave_B.Selector20 = bms_Slave_B.CellT_out[0];
    bms_Slave_B.Selector21 = bms_Slave_B.CellT_out[1];
    bms_Slave_B.Selector22 = bms_Slave_B.CellT_out[2];
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.ID = 403161332U;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[7] = 0;

    {
      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.Selector20);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[0] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.Selector21);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[1] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        int32_T packingValue = 0;

        {
          int32_T result = (int32_T) (bms_Slave_B.Selector22);
          result = (int32_T) (result - -40);
          packingValue = result;
        }

        if (packingValue < 0) {
          packingValue = 0;
        }

        {
          uint8_T packedValue;
          if (packingValue > (int32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (packingValue < (int32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (packingValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_CellTemp_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_CellTemp_Pack.ID != INVALID_CAN_ID) ) {
        if ((403161332 == bms_Slave_B.CMC_Chrger_CellTemp_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_CellTemp_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_CellTemp_Data[0],
                        bms_Slave_B.CMC_Chrger_CellTemp_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_CellTemp_ID =
            bms_Slave_B.CMC_Chrger_CellTemp_Pack.ID;
          bms_Slave_B.CMC_Chrger_CellTemp_Len =
            bms_Slave_B.CMC_Chrger_CellTemp_Pack.Length;
        }
      }
    }

    bms_Slave_B.Gain = 0.001F * (real32_T)bms_Slave_B.Current;
    bms_Slave_B.Gain2 = 0.001F * (real32_T)bms_Slave_B.CellV_max;
    bms_Slave_B.Gain1 = 0.001F * (real32_T)ABI_AdcSamplingData.Bat_Vol;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.ID = 403226868U;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[7] = 0;

    {
      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain;
          result = (result - -3000.0F) * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[7] | (uint8_T)
                ((uint16_T)(packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[6] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.SOC_Rpt;
          outValue = roundf(result);
        }

        {
          uint8_T packedValue;
          if (outValue > (real32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.SOH;
          outValue = roundf(result);
        }

        {
          uint8_T packedValue;
          if (outValue > (real32_T)(255)) {
            packedValue = (uint8_T) 255;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint8_T) 0;
          } else {
            packedValue = (uint8_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain2;
          result = result * (1 / 0.001F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[3] | (uint8_T)
                ((uint16_T)(packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[2] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Gain1;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint16_T packedValue;
          if (outValue > (real32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint16_T) 0;
          } else {
            packedValue = (uint16_T) (outValue);
          }

          {
            {
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[1] | (uint8_T)
                ((uint16_T)(packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Statistics_Pack.Data[0] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Statistics_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Statistics_Pack.ID != INVALID_CAN_ID) ) {
        if ((403226868 == bms_Slave_B.CMC_Chrger_Statistics_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Statistics_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Statistics_Data[0],
                        bms_Slave_B.CMC_Chrger_Statistics_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Statistics_ID =
            bms_Slave_B.CMC_Chrger_Statistics_Pack.ID;
          bms_Slave_B.CMC_Chrger_Statistics_Len =
            bms_Slave_B.CMC_Chrger_Statistics_Pack.Length;
        }
      }
    }

    bms_Slave_B.CMC_Chrger_Alarm_Pack.ID = 403292404U;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_1);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[0] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_2);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[1] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_3);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.CMC_Alarm_4);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Alarm_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Alarm_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Alarm_Pack.ID != INVALID_CAN_ID) ) {
        if ((403292404 == bms_Slave_B.CMC_Chrger_Alarm_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Alarm_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Alarm_Data[0],
                        bms_Slave_B.CMC_Chrger_Alarm_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Alarm_ID = bms_Slave_B.CMC_Chrger_Alarm_Pack.ID;
          bms_Slave_B.CMC_Chrger_Alarm_Len =
            bms_Slave_B.CMC_Chrger_Alarm_Pack.Length;
        }
      }
    }

    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.ID = 403357940U;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[0]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[0] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[1]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[1] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[2]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[3]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[4]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[5]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[6]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[6] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[7]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_BatteryID1_Pack.ID != INVALID_CAN_ID) ) {
        if ((403357940 == bms_Slave_B.CMC_Chrger_BatteryID1_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_BatteryID1_Data[0],
                        bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_BatteryID1_ID =
            bms_Slave_B.CMC_Chrger_BatteryID1_Pack.ID;
          bms_Slave_B.CMC_Chrger_BatteryID1_Len =
            bms_Slave_B.CMC_Chrger_BatteryID1_Pack.Length;
        }
      }
    }

    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.ID = 403423476U;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[9]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[1] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[10]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[11]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[12]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[13]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[14]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[6] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[15]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[8]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data[0] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_BatteryID2_Pack.ID != INVALID_CAN_ID) ) {
        if ((403423476 == bms_Slave_B.CMC_Chrger_BatteryID2_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_BatteryID2_Data[0],
                        bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_BatteryID2_ID =
            bms_Slave_B.CMC_Chrger_BatteryID2_Pack.ID;
          bms_Slave_B.CMC_Chrger_BatteryID2_Len =
            bms_Slave_B.CMC_Chrger_BatteryID2_Pack.Length;
        }
      }
    }

    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.ID = 403489012U;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[16]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[0] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[0] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[17]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[1] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[2] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[6] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_ID[18]);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_BatteryID3_Pack.ID != INVALID_CAN_ID) ) {
        if ((403489012 == bms_Slave_B.CMC_Chrger_BatteryID3_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_BatteryID3_Data[0],
                        bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_BatteryID3_ID =
            bms_Slave_B.CMC_Chrger_BatteryID3_Pack.ID;
          bms_Slave_B.CMC_Chrger_BatteryID3_Len =
            bms_Slave_B.CMC_Chrger_BatteryID3_Pack.Length;
        }
      }
    }

    bms_Slave_B.Switch1 = (uint8_T)(bms_Slave_DW.udTime1_DSTATE + 1U);
    bms_Slave_DW.udTime1_DSTATE = bms_Slave_B.Switch1;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.ID = 403554548U;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Length = 8U;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Extended = 1U;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Remote = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[0] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[1] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[2] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[3] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[4] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[5] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[6] = 0;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Switch1);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[4] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[4] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Battery_type);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[3] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[3] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (((uint8_T)1U));
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[2] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[2] | (uint8_T)
                ((uint16_T)(packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[1] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[1] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (Manu_code);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[7] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[7] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (CellV_num);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[6] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[6] | (uint8_T)
                (packedValue);
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (CellT_num);
          packingValue = result;
        }

        {
          uint8_T packedValue;
          packedValue = (uint8_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[5] =
                bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data[5] | (uint8_T)
                (packedValue);
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Length) &&
          (bms_Slave_B.CMC_Chrger_Factory_Param_Pack.ID != INVALID_CAN_ID) ) {
        if ((403554548 == bms_Slave_B.CMC_Chrger_Factory_Param_Pack.ID) && (1U ==
             bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_Chrger_Factory_Param_Data[0],
                        bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_Chrger_Factory_Param_ID =
            bms_Slave_B.CMC_Chrger_Factory_Param_Pack.ID;
          bms_Slave_B.CMC_Chrger_Factory_Param_Len =
            bms_Slave_B.CMC_Chrger_Factory_Param_Pack.Length;
        }
      }
    }

    bms_Slave_B.Selector23 = bms_Slave_B.CellV_OUT_p[0];
    bms_Slave_B.Selector24 = bms_Slave_B.CellV_OUT_p[1];
    bms_Slave_B.Selector31 = bms_Slave_B.CellV_OUT_p[2];
    bms_Slave_B.Selector32 = bms_Slave_B.CellV_OUT_p[3];
    bms_Slave_B.CMC_CellV_1_Pack.ID = 513U;
    bms_Slave_B.CMC_CellV_1_Pack.Length = 8U;
    bms_Slave_B.CMC_CellV_1_Pack.Extended = 0U;
    bms_Slave_B.CMC_CellV_1_Pack.Remote = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[0] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[1] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[2] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[3] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[4] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[5] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[6] = 0;
    bms_Slave_B.CMC_CellV_1_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector23);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_1_Pack.Data[1] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_1_Pack.Data[0] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector24);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_1_Pack.Data[3] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_1_Pack.Data[2] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector31);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_1_Pack.Data[5] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_1_Pack.Data[4] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector32);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_1_Pack.Data[7] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_1_Pack.Data[6] =
                bms_Slave_B.CMC_CellV_1_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_CellV_1_Pack.Length) &&
          (bms_Slave_B.CMC_CellV_1_Pack.ID != INVALID_CAN_ID) ) {
        if ((513 == bms_Slave_B.CMC_CellV_1_Pack.ID) && (0U ==
             bms_Slave_B.CMC_CellV_1_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_CellV_1_Data[0],
                        bms_Slave_B.CMC_CellV_1_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_CellV_1_ID = bms_Slave_B.CMC_CellV_1_Pack.ID;
          bms_Slave_B.CMC_CellV_1_Len = bms_Slave_B.CMC_CellV_1_Pack.Length;
        }
      }
    }

    bms_Slave_B.Selector33 = bms_Slave_B.CellV_OUT_p[4];
    bms_Slave_B.Selector34 = bms_Slave_B.CellV_OUT_p[5];
    bms_Slave_B.Selector35 = bms_Slave_B.CellV_OUT_p[6];
    bms_Slave_B.Selector36 = bms_Slave_B.CellV_OUT_p[7];
    bms_Slave_B.CMC_CellV_2_Pack.ID = 529U;
    bms_Slave_B.CMC_CellV_2_Pack.Length = 8U;
    bms_Slave_B.CMC_CellV_2_Pack.Extended = 0U;
    bms_Slave_B.CMC_CellV_2_Pack.Remote = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[0] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[1] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[2] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[3] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[4] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[5] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[6] = 0;
    bms_Slave_B.CMC_CellV_2_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector33);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_2_Pack.Data[1] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_2_Pack.Data[0] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector34);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_2_Pack.Data[3] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_2_Pack.Data[2] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector35);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_2_Pack.Data[5] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_2_Pack.Data[4] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector36);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_2_Pack.Data[7] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_2_Pack.Data[6] =
                bms_Slave_B.CMC_CellV_2_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_CellV_2_Pack.Length) &&
          (bms_Slave_B.CMC_CellV_2_Pack.ID != INVALID_CAN_ID) ) {
        if ((529 == bms_Slave_B.CMC_CellV_2_Pack.ID) && (0U ==
             bms_Slave_B.CMC_CellV_2_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_CellV_2_Data[0],
                        bms_Slave_B.CMC_CellV_2_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_CellV_2_ID = bms_Slave_B.CMC_CellV_2_Pack.ID;
          bms_Slave_B.CMC_CellV_2_Len = bms_Slave_B.CMC_CellV_2_Pack.Length;
        }
      }
    }

    bms_Slave_B.Selector37 = bms_Slave_B.CellV_OUT_p[9];
    bms_Slave_B.Selector38 = bms_Slave_B.CellV_OUT_p[10];
    bms_Slave_B.Selector25 = bms_Slave_B.CellV_OUT_p[11];
    bms_Slave_B.Selector26 = bms_Slave_B.CellV_OUT_p[8];
    bms_Slave_B.CMC_CellV_3_Pack.ID = 545U;
    bms_Slave_B.CMC_CellV_3_Pack.Length = 8U;
    bms_Slave_B.CMC_CellV_3_Pack.Extended = 0U;
    bms_Slave_B.CMC_CellV_3_Pack.Remote = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[0] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[1] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[2] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[3] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[4] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[5] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[6] = 0;
    bms_Slave_B.CMC_CellV_3_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector37);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_3_Pack.Data[3] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_3_Pack.Data[2] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector38);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_3_Pack.Data[5] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_3_Pack.Data[4] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector25);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_3_Pack.Data[7] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_3_Pack.Data[6] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector26);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_3_Pack.Data[1] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_3_Pack.Data[0] =
                bms_Slave_B.CMC_CellV_3_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_CellV_3_Pack.Length) &&
          (bms_Slave_B.CMC_CellV_3_Pack.ID != INVALID_CAN_ID) ) {
        if ((545 == bms_Slave_B.CMC_CellV_3_Pack.ID) && (0U ==
             bms_Slave_B.CMC_CellV_3_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_CellV_3_Data[0],
                        bms_Slave_B.CMC_CellV_3_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_CellV_3_ID = bms_Slave_B.CMC_CellV_3_Pack.ID;
          bms_Slave_B.CMC_CellV_3_Len = bms_Slave_B.CMC_CellV_3_Pack.Length;
        }
      }
    }

    bms_Slave_B.Selector27 = bms_Slave_B.CellV_OUT_p[12];
    bms_Slave_B.Selector28 = bms_Slave_B.CellV_OUT_p[13];
    bms_Slave_B.Selector29 = bms_Slave_B.CellV_OUT_p[14];
    bms_Slave_B.Selector30 = bms_Slave_B.CellV_OUT_p[15];
    bms_Slave_B.CMC_CellV_4_Pack.ID = 561U;
    bms_Slave_B.CMC_CellV_4_Pack.Length = 8U;
    bms_Slave_B.CMC_CellV_4_Pack.Extended = 0U;
    bms_Slave_B.CMC_CellV_4_Pack.Remote = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[0] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[1] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[2] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[3] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[4] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[5] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[6] = 0;
    bms_Slave_B.CMC_CellV_4_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector27);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_4_Pack.Data[1] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[1] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_4_Pack.Data[0] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[0] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector28);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_4_Pack.Data[3] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[3] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_4_Pack.Data[2] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[2] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector29);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_4_Pack.Data[5] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[5] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_4_Pack.Data[4] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[4] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Selector30);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          packedValue = (uint16_T) (packingValue);

          {
            {
              bms_Slave_B.CMC_CellV_4_Pack.Data[7] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[7] | (uint8_T)((uint16_T)
                (packedValue & (uint16_T)0xFFU));
              bms_Slave_B.CMC_CellV_4_Pack.Data[6] =
                bms_Slave_B.CMC_CellV_4_Pack.Data[6] | (uint8_T)((uint16_T)
                ((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.CMC_CellV_4_Pack.Length) &&
          (bms_Slave_B.CMC_CellV_4_Pack.ID != INVALID_CAN_ID) ) {
        if ((561 == bms_Slave_B.CMC_CellV_4_Pack.ID) && (0U ==
             bms_Slave_B.CMC_CellV_4_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.CMC_CellV_4_Data[0],
                        bms_Slave_B.CMC_CellV_4_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.CMC_CellV_4_ID = bms_Slave_B.CMC_CellV_4_Pack.ID;
          bms_Slave_B.CMC_CellV_4_Len = bms_Slave_B.CMC_CellV_4_Pack.Length;
        }
      }
    }

    bms_Slave_B.BalaSta_CycleCapacity_Pack.ID = 625U;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Length = 8U;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Extended = 0U;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Remote = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[0] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[1] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[2] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[3] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[4] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[5] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[6] = 0;
    bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[7] = 0;

    {
      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Balance_State);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          if (packingValue > (uint32_T)(65535)) {
            packedValue = (uint16_T) 65535;
          } else {
            packedValue = (uint16_T) (packingValue);
          }

          {
            {
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[3] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[3] | (uint8_T)
                ((uint16_T)(packedValue & (uint16_T)0xFFU));
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[2] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[2] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0xFF00U) >> 8));
            }
          }
        }
      }

      {
        real32_T outValue = 0;

        {
          real32_T result = bms_Slave_B.Switch9;
          result = result * (1 / 0.1F);
          outValue = roundf(result);
        }

        {
          uint32_T packedValue;
          if (outValue > (real32_T)(16777215)) {
            packedValue = (uint32_T) 16777215;
          } else if (outValue < (real32_T)(0)) {
            packedValue = (uint32_T) 0;
          } else {
            packedValue = (uint32_T) (outValue);
          }

          {
            {
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[6] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[6] | (uint8_T)
                ((uint32_T)(packedValue & (uint32_T)0xFFU));
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[5] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[5] | (uint8_T)
                ((uint32_T)((uint32_T)(packedValue & (uint32_T)0xFF00U) >> 8));
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[4] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[4] | (uint8_T)
                ((uint32_T)((uint32_T)(packedValue & (uint32_T)0xFF0000U) >> 16));
            }
          }
        }
      }

      {
        uint32_T packingValue = 0;

        {
          uint32_T result = (uint32_T) (bms_Slave_B.Cycle_Num);
          packingValue = result;
        }

        {
          uint16_T packedValue;
          if (packingValue > (uint16_T)(8191)) {
            packedValue = (uint16_T) 8191;
          } else {
            packedValue = (uint16_T) (packingValue);
          }

          {
            {
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[1] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[1] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0x1FU) << 3));
              bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[0] =
                bms_Slave_B.BalaSta_CycleCapacity_Pack.Data[0] | (uint8_T)
                ((uint16_T)((uint16_T)(packedValue & (uint16_T)0x1FE0U) >> 5));
            }
          }
        }
      }
    }

    {
      if ((8 == bms_Slave_B.BalaSta_CycleCapacity_Pack.Length) &&
          (bms_Slave_B.BalaSta_CycleCapacity_Pack.ID != INVALID_CAN_ID) ) {
        if ((625 == bms_Slave_B.BalaSta_CycleCapacity_Pack.ID) && (0U ==
             bms_Slave_B.BalaSta_CycleCapacity_Pack.Extended) ) {
          (void) memcpy(&bms_Slave_B.BalaSta_CycleCapacity_Data[0],
                        bms_Slave_B.BalaSta_CycleCapacity_Pack.Data,
                        8 * sizeof(uint8_T));
          bms_Slave_B.BalaSta_CycleCapacity_ID =
            bms_Slave_B.BalaSta_CycleCapacity_Pack.ID;
          bms_Slave_B.BalaSta_CycleCapacity_Len =
            bms_Slave_B.BalaSta_CycleCapacity_Pack.Length;
        }
      }
    }

    if (bms_Slave_B.LogicalOperator20) {
      RTE_CAN_SendCanDataById(0, bms_Slave_B.BMS_Chrg_Request_ID,
        &bms_Slave_B.BMS_Chrg_Request_Data[0], bms_Slave_B.BMS_Chrg_Request_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Cell_1_ID,
        &bms_Slave_B.CMC_Chrger_Cell_1_Data[0],
        bms_Slave_B.CMC_Chrger_Cell_1_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Cell_2_ID,
        &bms_Slave_B.CMC_Chrger_Cell_2_Data[0],
        bms_Slave_B.CMC_Chrger_Cell_2_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Cell_3_ID,
        &bms_Slave_B.CMC_Chrger_Cell_3_Data[0],
        bms_Slave_B.CMC_Chrger_Cell_3_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Cell_4_ID,
        &bms_Slave_B.CMC_Chrger_Cell_4_Data[0],
        bms_Slave_B.CMC_Chrger_Cell_4_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Cell_5_ID,
        &bms_Slave_B.CMC_Chrger_Cell_5_Data[0],
        bms_Slave_B.CMC_Chrger_Cell_5_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_CellTemp_ID,
        &bms_Slave_B.CMC_Chrger_CellTemp_Data[0],
        bms_Slave_B.CMC_Chrger_CellTemp_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Statistics_ID,
        &bms_Slave_B.CMC_Chrger_Statistics_Data[0],
        bms_Slave_B.CMC_Chrger_Statistics_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Alarm_ID,
        &bms_Slave_B.CMC_Chrger_Alarm_Data[0], bms_Slave_B.CMC_Chrger_Alarm_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_BatteryID1_ID,
        &bms_Slave_B.CMC_Chrger_BatteryID1_Data[0],
        bms_Slave_B.CMC_Chrger_BatteryID1_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_BatteryID2_ID,
        &bms_Slave_B.CMC_Chrger_BatteryID2_Data[0],
        bms_Slave_B.CMC_Chrger_BatteryID2_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_BatteryID3_ID,
        &bms_Slave_B.CMC_Chrger_BatteryID3_Data[0],
        bms_Slave_B.CMC_Chrger_BatteryID3_Len);
      RTE_CAN_SendCanDataById(0, bms_Slave_B.CMC_Chrger_Factory_Param_ID,
        &bms_Slave_B.CMC_Chrger_Factory_Param_Data[0],
        bms_Slave_B.CMC_Chrger_Factory_Param_Len);
    }

    if ((!bms_Slave_B.LogicalOperator20) && ((Receive_Flg >= 1) && (Receive_Flg <=
          8))) {
      rtb_Gain10 = bms_Slave_B.CMC_CellV_1_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.CMC_CellV_1_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.CMC_CellV_1_Data[0],
        bms_Slave_B.CMC_CellV_1_Len);
      rtb_Gain10 = bms_Slave_B.CMC_CellV_2_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.CMC_CellV_2_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.CMC_CellV_2_Data[0],
        bms_Slave_B.CMC_CellV_2_Len);
      rtb_Gain10 = bms_Slave_B.CMC_CellV_3_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.CMC_CellV_3_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.CMC_CellV_3_Data[0],
        bms_Slave_B.CMC_CellV_3_Len);
      rtb_Gain10 = bms_Slave_B.CMC_CellV_4_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.CMC_CellV_4_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc, &bms_Slave_B.CMC_CellV_4_Data[0],
        bms_Slave_B.CMC_CellV_4_Len);
      rtb_Gain10 = bms_Slave_B.BalaSta_CycleCapacity_ID + Receive_Flg;
      if (rtb_Gain10 < bms_Slave_B.BalaSta_CycleCapacity_ID) {
        rtb_Gain10 = MAX_uint32_T;
      }

      CellV_acc = rtb_Gain10 - 1U;
      if (rtb_Gain10 - 1U > rtb_Gain10) {
        CellV_acc = 0U;
      }

      RTE_CAN_SendCanDataById(0, CellV_acc,
        &bms_Slave_B.BalaSta_CycleCapacity_Data[0],
        bms_Slave_B.BalaSta_CycleCapacity_Len);
    }
  }

  if (bms_Slave_DW.counter % 100 == 0) {
    bms_Slave_DW.counter = 0U;
  }

  i_0 = bms_Slave_DW.counter + 1;
  if (bms_Slave_DW.counter + 1 > 65535) {
    i_0 = 65535;
  }

  bms_Slave_DW.counter = (uint16_T)i_0;
  CH_CAN_Flg.fc_r_ParaSet_flg = fc_r_ChrgData_flg_0;
  CH_CAN_Flg.fc_r_ChrgData_flg = fc_r_ParaSet_flg;
  CH_CAN_Flg.fc_r_cmcWake_flg = fc_r_cmcWake_flg_0;
  CH_CAN_Flg.fc_r_bmu_cmd_flg = fc_r_bmu_cmd_flg_0;
  rtb_RelationalOperator4_g = ((bms_Slave_DW.UnitDelay37_DSTATE == 0) &&
    (rtb_Low_Current != 0));
  if (bms_Slave_B.BMS_CurrOffset_Set_Valid_k != 0) {
    bms_Slave_DW.UnitDelay1_DSTATE_l = bms_Slave_B.BMS_CurrOffset_Set_Valid_k;
  }

  if (bms_Slave_DW.UnitDelay1_DSTATE_l != 0) {
    Receive_Flg = (uint8_T)bms_Slave_B.BMS_CurrOffset_Set_i;
  } else {
    i_0 = ABI_NVMData.CurrOffset_Cal - 10000;
    Receive_Flg = (uint8_T)i_0;
  }

  if (bms_Slave_DW.is_active_c26_bms_Slave == 0U) {
    bms_Slave_DW.is_active_c26_bms_Slave = 1U;
    bms_Slave_DW.is_c26_bms_Slave = bms_Slave_IN_INI;
    bms_Slave_B.CurrOffset_Cal_Add = Receive_Flg;
    bms_Slave_DW.T_b = 0U;
  } else {
    switch (bms_Slave_DW.is_c26_bms_Slave) {
     case bms_Slave_IN_Calibration1:
      if (bms_Slave_DW.T_b >= 5) {
        bms_Slave_DW.is_c26_bms_Slave = bms_Slave_IN_Calibration_Result;
        bms_Slave_B.CurrOffset_Cal_Add = -bms_Slave_DW.Cur / 5.0F;
      } else {
        i_0 = bms_Slave_DW.T_b + 1;
        if (bms_Slave_DW.T_b + 1 > 65535) {
          i_0 = 65535;
        }

        bms_Slave_DW.T_b = (uint16_T)i_0;
        bms_Slave_DW.Cur += (real32_T)rtb_Low_Current;
      }
      break;

     case bms_Slave_IN_Calibration_Result:
      if (rtb_RelationalOperator4_g && ((rtb_Low_Current < -50) ||
           (rtb_Low_Current > 50))) {
        bms_Slave_DW.is_c26_bms_Slave = bms_Slave_IN_Calibration1;
        bms_Slave_B.CurrOffset_Cal_Add = 0.0F;
        bms_Slave_DW.Cur = 0.0F;
        bms_Slave_DW.T_b = 0U;
      }
      break;

     default:
      if (rtb_RelationalOperator4_g && (bms_Slave_DW.T_b >= 500)) {
        bms_Slave_DW.is_c26_bms_Slave = bms_Slave_IN_Calibration1;
        bms_Slave_B.CurrOffset_Cal_Add = 0.0F;
        bms_Slave_DW.Cur = 0.0F;
        bms_Slave_DW.T_b = 0U;
      } else {
        i_0 = bms_Slave_DW.T_b + 1;
        if (bms_Slave_DW.T_b + 1 > 65535) {
          i_0 = 65535;
        }

        bms_Slave_DW.T_b = (uint16_T)i_0;
      }
      break;
    }
  }

  if ((bms_Slave_DW.UnitDelay2_DSTATE_b == 1) &&
      (bms_Slave_B.Open_The_Barn_door_c == 0)) {
    bms_Slave_DW.UnitDelay3_DSTATE_e = bms_Slave_B.Real_SOC_Max;
  }

  if ((bms_Slave_DW.UnitDelay_DSTATE_e == 0) &&
      (bms_Slave_B.Open_The_Barn_door_c == 1)) {
    bms_Slave_DW.UnitDelay1_DSTATE_a = bms_Slave_B.Real_SOC_Max;
  }

  if (bms_Slave_B.CellV_TgtReach != 0) {
    bms_Slave_DW.UnitDelay9_DSTATE = (bms_Slave_B.CellV_TgtReach != 0);
  }

  bms_Slave_DW.UnitDelay8_DSTATE_k = (rtb_Switch_ONOFF ||
    bms_Slave_DW.UnitDelay8_DSTATE_k);
  if (ABI_DID.writeSOH_flg != 0) {
    bms_Slave_DW.UnitDelay6_DSTATE = 1U;
  }

  if (bms_Slave_DW.UnitDelay6_DSTATE != 0) {
    Ref1 = 0.100000381F * (real32_T)ABI_DID.writeSOH;
  } else {
    if (rtb_Divide6 > 100.0F) {
      rtb_Divide6 = 100.0F;
    } else if (rtb_Divide6 < 70.0F) {
      rtb_Divide6 = 70.0F;
    }

    Ref = bms_Slave_DW.UnitDelay3_DSTATE_e - bms_Slave_DW.UnitDelay1_DSTATE_a;
    if (!(Ref > 80.0F)) {
      Ref = 100.0F;
    }

    Ref1 = bms_Slave_DW.UnitDelay5_DSTATE_a / (Ref * (real32_T)Capacity_Rate /
      100.0F * DOD);
    Ref = rtb_Divide6 - Ref1;
    if ((!bms_Slave_DW.UnitDelay9_DSTATE) || (!bms_Slave_DW.UnitDelay8_DSTATE_k)
        || (bms_Slave_B.CellT_max > 45) || (bms_Slave_B.CellT_max < 20) ||
        (!(Ref <= 1.0F)) || (!(Ref >= 0.0F)) || (!(Ref1 > 70.0F))) {
      Ref1 = rtb_Divide6;
    }

    Ref1 = fmaxf(Ref1, look1_iu16lu16n16yu8tu_6zSHy4Dc(bms_Slave_B.Cycle_Num, (
      const uint16_T *)&Cycle_NUM[0], (const uint8_T *)&SOH_CAL[0], 31U));
  }

  if (Ref1 > 100.0F) {
    bms_Slave_DW.UnitDelay15_DSTATE = 100.0F;
  } else if (Ref1 < 70.0F) {
    bms_Slave_DW.UnitDelay15_DSTATE = 70.0F;
  } else {
    bms_Slave_DW.UnitDelay15_DSTATE = Ref1;
  }

  bms_Slave_DW.UnitDelay13_DSTATE = false;
  bms_Slave_DW.UnitDelay36_DSTATE = 0U;
  bms_Slave_DW.UnitDelay37_DSTATE = bms_Slave_B.BMS_PwrTrainConnectSta;
  bms_Slave_DW.UnitDelay8_DSTATE = bms_Slave_B.Real_SOC_Max;
  bms_Slave_DW.UnitDelay11_DSTATE = bms_Slave_B.SOC_Act;
  bms_Slave_DW.UnitDelay24_DSTATE = bms_Slave_DW.UnitDelay27_DSTATE;
  bms_Slave_DW.UnitDelay35_DSTATE = bms_Slave_B.Balance_o3;
  bms_Slave_DW.UnitDelay5_DSTATE = bms_Slave_B.SOC_Rpt;
  bms_Slave_DW.UnitDelay4_DSTATE_b = bms_Slave_B.Relay_En;
  bms_Slave_DW.UnitDelay1_DSTATE_i = bms_Slave_B.SOC_Correct_Flag;
  bms_Slave_DW.UnitDelay30_DSTATE = fc_r_ParaSet_flg;
  bms_Slave_DW.UnitDelay4_DSTATE = bms_Slave_DW.UnitDelay10_DSTATE_m;
  bms_Slave_DW.UnitDelay2_DSTATE = Mode;
  bms_Slave_DW.UnitDelay3_DSTATE = bms_Slave_B.SOC_Rpt;
  bms_Slave_DW.UnitDelay_DSTATE_j = bms_Slave_B.Err_Level_a;
  bms_Slave_DW.UnitDelay18_DSTATE = bms_Slave_B.ChrgPower_Limit_0;
  bms_Slave_DW.UnitDelay16_DSTATE = bms_Slave_B.DisChrgPower_Limit_0;
  bms_Slave_DW.UnitDelay17_DSTATE = bms_Slave_B.ChrgPower_Limit_50;
  bms_Slave_DW.UnitDelay21_DSTATE = bms_Slave_B.DisChrgPower_Limit_50;
  bms_Slave_DW.UnitDelay2_DSTATE_b = bms_Slave_B.Open_The_Barn_door_c;
  bms_Slave_DW.UnitDelay_DSTATE_e = bms_Slave_B.Open_The_Barn_door_c;
}

void bms_Slave_initialize(void)
{
  rt_InitInfAndNaN(sizeof(real_T));

  {
    bms_Slave_B.BMS_Chrg_Request_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Cell_1_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Cell_2_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Cell_3_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Cell_4_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Cell_5_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_CellTemp_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Statistics_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Alarm_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_BatteryID1_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_BatteryID2_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_BatteryID3_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Chrger_Factory_Param_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_CellV_1_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_CellV_2_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_CellV_3_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_CellV_4_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.BalaSta_CycleCapacity_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_CellT_SOC_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.Max_Con_Current_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.CMC_Current_Falt_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.Chrger_CMC_Wake_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.Chrger_CMC_Chrg_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.BMU_CMD_Pack = CAN_DATATYPE_GROUND;
    bms_Slave_B.Para_Set_BMS_Pack = CAN_DATATYPE_GROUND;
  }

  SOC_GX_initialize(rtmGetErrorStatusPointer(bms_Slave_M),
                    &(bms_Slave_DW.SOC_InstanceData.rtm));
  Balance_initialize(rtmGetErrorStatusPointer(bms_Slave_M),
                     &(bms_Slave_DW.Balance_InstanceData.rtm));

  {
    int32_T i;
    boolean_T Alarm_flg_b;
    bms_Slave_DW.UnitDelay15_DSTATE = 100.0F;
    ABI_AdcSamplingData.Interlock = 0U;
    ABI_AdcSamplingData.BoardVoltage_mV = 0U;
    ABI_AdcSamplingData.Bat_Vol = 0U;
    ABI_AdcSamplingData.CPVoltage_mV = 0U;
    ABI_AdcSamplingData.CC_R = 0U;
    ABI_AdcSamplingData.CC2Voltage_mV = 0U;
    ABI_AdcSamplingData.Shut_NTC1_AD = 0U;
    ABI_AdcSamplingData.MOS_NTC2_AD = 0U;
    ABI_AdcSamplingData.DC_PosTemp_AD = 0U;
    ABI_AdcSamplingData.DC_NegTemp_AD = 0U;
    ABI_AdcSamplingData.Current_AD = 0U;
    ABI_AdcSamplingData.PackID_AD = 0U;
    ABI_WakeState.FastCharge_WakeState = 0U;
    ABI_WakeState.RTC_WakeState = 0U;
    ABI_WakeState.CP_WakeState = 0U;
    bms_Slave_B.AFE_Signal.CellV_Valid = 0U;
    bms_Slave_B.AFE_Signal.CellT_Valid = 0U;
    bms_Slave_B.AFE_Signal.Chain_Update = 0U;
    bms_Slave_B.AFE_Signal.DischrgMOS_State = 0U;
    bms_Slave_B.AFE_Signal.ChrgMOS_State = 0U;
    bms_Slave_B.AFE_Signal.Current_Valid = 0U;
    bms_Slave_B.AFE_Signal.INI_Finish_flg = 0U;
    bms_Slave_B.AFE_Signal.CellV_Sample_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.ICU_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.TBOX_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.BCM_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.INV_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.OBC_lost_flg = 0U;
    bms_Slave_B.AFE_Signal.ACAN_BUSOFF_flg = 0U;
    bms_Slave_B.AFE_Signal.Balance_Diagnose_flg = 0U;
    bms_Slave_B.AFE_Signal.CellV_low_lv3_latch = 0U;
    bms_Slave_B.AFE_Signal.CellV_Over_lv3_latch = 0U;
    bms_Slave_B.AFE_Signal.SOH_low_lv1_latch = 0U;
    bms_Slave_B.AFE_Signal.SOH_low_lv2_latch = 0U;
    bms_Slave_B.AFE_Signal.Shunt_Zerodrift_latch = 0U;
    ABI_NVMData.SOCDisp = 0U;
    ABI_NVMData.ActSOC = 0U;
    ABI_NVMData.SOH = 0U;
    ABI_NVMData.Cycle_Num = 0U;
    ABI_NVMData.FullChrg_Flg = 0U;
    ABI_NVMData.BatteryPackChargeCapacity = 0U;
    ABI_NVMData.UsedSOC = 0U;
    ABI_NVMData.RealSOC = 0U;
    for (i = 0; i < 7; i++) {
      ABI_NVMData.VehicleConfiguration[i] = 0U;
      ABI_NVMData.FunctionConfiguration[i] = 0U;
    }

    for (i = 0; i < 10; i++) {
      ABI_NVMData.VehicleFunctionConfiguration_01[i] = 0U;
    }

    for (i = 0; i < 17; i++) {
      ABI_NVMData.VIN[i] = 0U;
    }

    ABI_NVMData.BMSStoredTime.R = 0U;
    ABI_NVMData.BMSStoredTime.B = 0U;
    ABI_NVMData.Power_Consom = 0U;
    ABI_NVMData.BMS_CellDRCnt = 0U;
    ABI_NVMData.SOC_Ave_Read = 0U;
    ABI_NVMData.Mileage_Ave_Read = 0U;
    ABI_NVMData.CurrOffset_Cal = 0U;
    ABI_NVMData.Mileage = 0U;
    ABI_NVMData.Target_SOC = 0U;
    ABI_NVMData.Chrg_Num = 0U;
    fc_r_ParaSet_flg_0 = 0U;
    bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_a);
    Alarm_Recov_sys_cell_Init(&bms_Slave_B.Alarm_flg_e);
    Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_h);
    bms_Slave_Diagnose_system_Init();
    SOC_GX_Init(&(bms_Slave_DW.SOC_InstanceData.rtdw));
    bms_Slave_Alarm_Recov_sys_Init(&bms_Slave_B.Alarm_flg_jl);
    bms_Slave_ChrgMode_Cal_Init();
    bms_Slave_DC_ChrgSig_Init();
    bms_Slave_SOP_Init();
    bms_Slave_Alarm_Recov_sys_Init(&Alarm_flg_b);
    bms_Slave_DW.i = 1U;
    fc_r_cmcWake_flg_0 = 0U;
    fc_r_bmu_cmd_flg_0 = 0U;
    fc_r_ChrgData_flg_0 = 0U;
  }
}

void bms_Slave_terminate(void)
{
}
